summaryrefslogtreecommitdiff
path: root/chromium/components/arc/arc_service_manager.h
blob: 1e84e21d97b7b5924ddf4ffddd7c25cd4060eb04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_
#define COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_

#include <memory>

#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "components/signin/core/account_id/account_id.h"

namespace content {
class BrowserContext;
}  // namespace content

namespace arc {

class ArcBridgeService;

// Holds ARC related global information. Specifically, it owns ArcBridgeService
// instance.
// TODO(hidehiko): Consider to migrate into another global ARC class, such as
// ArcSessionManager or ArcServiceLauncher.
class ArcServiceManager {
 public:
  ArcServiceManager();
  ~ArcServiceManager();

  // Returns the current BrowserContext which ARC is allowed.
  // This is workaround to split the dependency from chrome/.
  // TODO(hidehiko): Remove this when we move IsArcAllowedForProfile() to
  // components/arc.
  content::BrowserContext* browser_context() { return browser_context_; }

  // TODO(hidehiko): Remove this when we move IsArcAllowedForProfile() to
  // components/arc. See browser_context() for details.
  void set_browser_context(content::BrowserContext* browser_context) {
    browser_context_ = browser_context;
  }

  // Returns the current AccountID which ARC is allowed.
  // This is workaround to split the dependency from chrome/.
  // TODO(hidehiko): Remove this when we move IsArcAllowedForProfile() to
  // components/arc.
  const AccountId& account_id() const { return account_id_; }

  // TODO(hidehiko): Remove this when we move IsArcAllowedForProfile() to
  // components/arc.
  void set_account_id(const AccountId& account_id) { account_id_ = account_id; }

  // |arc_bridge_service| can only be accessed on the thread that this
  // class was created on.
  ArcBridgeService* arc_bridge_service();

  // Gets the global instance of the ARC Service Manager. This can only be
  // called on the thread that this class was created on.
  static ArcServiceManager* Get();

 private:
  THREAD_CHECKER(thread_checker_);

  std::unique_ptr<ArcBridgeService> arc_bridge_service_;

  // This holds the pointer to the BrowserContext (practically Profile)
  // which is allowed to use ARC.
  // This is set just before BrowserContextKeyedService classes are
  // instantiated.
  // So, in BrowserContextKeyedServiceFactory::BuildServiceInstanceFor(),
  // given BrowserContext pointer can be compared to this to check if it is
  // allowed to use ARC.
  // TODO(hidehiko): Remove this when we move IsArcAllowedForProfile() to
  // components/arc. See browser_context() for details.
  content::BrowserContext* browser_context_ = nullptr;

  // This holds the AccountId corresponding to the |browser_context_|.
  // TODO(hidehiko): Remove this when we move IsArcAllowedForProfile() to
  // components/arc. See browser_context() for details.
  AccountId account_id_;

  DISALLOW_COPY_AND_ASSIGN(ArcServiceManager);
};

}  // namespace arc

#endif  // COMPONENTS_ARC_ARC_SERVICE_MANAGER_H_