• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_
6 #define CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/task.h"
14 #include "chrome/browser/policy/enterprise_install_attributes.h"
15 
16 class PrefService;
17 class TestingBrowserProcess;
18 class TokenService;
19 
20 namespace net {
21 class URLRequestContextGetter;
22 }
23 
24 namespace policy {
25 
26 class CloudPolicySubsystem;
27 class ConfigurationPolicyProvider;
28 class DevicePolicyIdentityStrategy;
29 
30 // Manages the lifecycle of browser-global policy infrastructure, such as the
31 // platform policy providers.
32 class BrowserPolicyConnector {
33  public:
34   BrowserPolicyConnector();
35   ~BrowserPolicyConnector();
36 
37   ConfigurationPolicyProvider* GetManagedPlatformProvider() const;
38   ConfigurationPolicyProvider* GetManagedCloudProvider() const;
39   ConfigurationPolicyProvider* GetRecommendedPlatformProvider() const;
40   ConfigurationPolicyProvider* GetRecommendedCloudProvider() const;
41 
42   // Returns a weak pointer to the CloudPolicySubsystem managed by this
43   // policy connector, or NULL if no such subsystem exists (i.e. when running
44   // outside ChromeOS).
cloud_policy_subsystem()45   CloudPolicySubsystem* cloud_policy_subsystem() {
46     return cloud_policy_subsystem_.get();
47   }
48 
49   // Used to set the credentials stored in the identity strategy associated
50   // with this policy connector.
51   void SetCredentials(const std::string& owner_email,
52                       const std::string& gaia_token);
53 
54   // Returns true if this device is managed by an enterprise (as opposed to
55   // a local owner).
56   bool IsEnterpriseManaged();
57 
58   // Locks the device to an enterprise domain.
59   EnterpriseInstallAttributes::LockResult LockDevice(const std::string& user);
60 
61   // Returns the enterprise domain if device is managed.
62   std::string GetEnterpriseDomain();
63 
64   // Exposes the StopAutoRetry() method of the CloudPolicySubsystem managed
65   // by this connector, which can be used to disable automatic
66   // retrying behavior.
67   void StopAutoRetry();
68 
69   // Initiates a policy fetch after a successful device registration.
70   void FetchPolicy();
71 
72  private:
73   friend class ::TestingBrowserProcess;
74 
75   static ConfigurationPolicyProvider* CreateManagedPlatformProvider();
76   static ConfigurationPolicyProvider* CreateRecommendedPlatformProvider();
77 
78   // Constructor for tests that allows tests to use fake platform policy
79   // providers instead of using the actual ones.
80   BrowserPolicyConnector(
81       ConfigurationPolicyProvider* managed_platform_provider,
82       ConfigurationPolicyProvider* recommended_platform_provider);
83 
84   // Activates the cloud policy subsystem.
85   void Initialize();
86 
87   scoped_ptr<ConfigurationPolicyProvider> managed_platform_provider_;
88   scoped_ptr<ConfigurationPolicyProvider> recommended_platform_provider_;
89 
90 #if defined(OS_CHROMEOS)
91   scoped_ptr<DevicePolicyIdentityStrategy> identity_strategy_;
92   scoped_ptr<EnterpriseInstallAttributes> install_attributes_;
93 #endif
94   scoped_ptr<CloudPolicySubsystem> cloud_policy_subsystem_;
95 
96   ScopedRunnableMethodFactory<BrowserPolicyConnector> method_factory_;
97 
98   DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnector);
99 };
100 
101 }  // namespace policy
102 
103 #endif  // CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_
104