Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: chrome/browser/policy/device_management_policy_provider.cc

Issue 4960003: Don't register gmail users at the device management server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/policy/device_management_policy_provider.h" 5 #include "chrome/browser/policy/device_management_policy_provider.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/task.h" 10 #include "base/task.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "chrome/browser/browser_thread.h" 12 #include "chrome/browser/browser_thread.h"
13 #include "chrome/browser/profile.h"
13 #include "chrome/browser/policy/device_management_backend.h" 14 #include "chrome/browser/policy/device_management_backend.h"
14 #include "chrome/browser/policy/device_management_policy_cache.h" 15 #include "chrome/browser/policy/device_management_policy_cache.h"
15 #include "chrome/browser/policy/device_token_fetcher.h" 16 #include "chrome/browser/policy/device_token_fetcher.h"
16 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/notification_service.h" 19 #include "chrome/common/notification_service.h"
19 #include "chrome/common/notification_type.h" 20 #include "chrome/common/notification_type.h"
20 21
21 namespace policy { 22 namespace policy {
22 23
(...skipping 21 matching lines...) Expand all
44 provider->InitializeAfterIOThreadExists(); 45 provider->InitializeAfterIOThreadExists();
45 } 46 }
46 47
47 private: 48 private:
48 base::WeakPtr<DeviceManagementPolicyProvider> provider_; 49 base::WeakPtr<DeviceManagementPolicyProvider> provider_;
49 }; 50 };
50 51
51 DeviceManagementPolicyProvider::DeviceManagementPolicyProvider( 52 DeviceManagementPolicyProvider::DeviceManagementPolicyProvider(
52 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list, 53 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list,
53 DeviceManagementBackend* backend, 54 DeviceManagementBackend* backend,
54 TokenService* token_service, 55 Profile* profile)
55 const FilePath& storage_dir)
56 : ConfigurationPolicyProvider(policy_list), 56 : ConfigurationPolicyProvider(policy_list),
57 backend_(backend), 57 backend_(backend),
58 token_service_(token_service), 58 profile_(profile),
59 storage_dir_(GetOrCreateDeviceManagementDir(storage_dir)), 59 storage_dir_(GetOrCreateDeviceManagementDir(profile_->GetPath())),
60 policy_request_pending_(false) { 60 policy_request_pending_(false) {
61 Initialize(); 61 Initialize();
62 } 62 }
63
64 DeviceManagementPolicyProvider::DeviceManagementPolicyProvider(
65 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list,
66 DeviceManagementBackend* backend,
67 Profile* profile,
68 DeviceTokenFetcher* token_fetcher)
69 : ConfigurationPolicyProvider(policy_list),
70 backend_(backend),
71 profile_(profile),
72 token_fetcher_(token_fetcher),
73 storage_dir_(GetOrCreateDeviceManagementDir(profile_->GetPath())),
74 policy_request_pending_(false) {
75 Initialize();
76 }
63 77
64 DeviceManagementPolicyProvider::~DeviceManagementPolicyProvider() {} 78 DeviceManagementPolicyProvider::~DeviceManagementPolicyProvider() {}
65 79
66 bool DeviceManagementPolicyProvider::Provide( 80 bool DeviceManagementPolicyProvider::Provide(
67 ConfigurationPolicyStoreInterface* policy_store) { 81 ConfigurationPolicyStoreInterface* policy_store) {
68 scoped_ptr<DictionaryValue> policies(cache_->GetPolicy()); 82 scoped_ptr<DictionaryValue> policies(cache_->GetPolicy());
69 DecodePolicyValueTree(policies.get(), policy_store); 83 DecodePolicyValueTree(policies.get(), policy_store);
70 return true; 84 return true;
71 } 85 }
72 86
(...skipping 21 matching lines...) Expand all
94 108
95 void DeviceManagementPolicyProvider::OnError( 109 void DeviceManagementPolicyProvider::OnError(
96 DeviceManagementBackend::ErrorCode code) { 110 DeviceManagementBackend::ErrorCode code) {
97 LOG(WARNING) << "could not provide policy from the device manager (error = " 111 LOG(WARNING) << "could not provide policy from the device manager (error = "
98 << code << ")"; 112 << code << ")";
99 policy_request_pending_ = false; 113 policy_request_pending_ = false;
100 // TODO(danno): do something sensible in the error case, perhaps retry later? 114 // TODO(danno): do something sensible in the error case, perhaps retry later?
101 } 115 }
102 116
103 void DeviceManagementPolicyProvider::Shutdown() { 117 void DeviceManagementPolicyProvider::Shutdown() {
104 token_service_ = NULL; 118 profile_ = NULL;
105 if (token_fetcher_) 119 if (token_fetcher_)
106 token_fetcher_->Shutdown(); 120 token_fetcher_->Shutdown();
107 } 121 }
108 122
109 void DeviceManagementPolicyProvider::Initialize() { 123 void DeviceManagementPolicyProvider::Initialize() {
110 registrar_.Add(this, 124 registrar_.Add(this,
111 NotificationType::DEVICE_TOKEN_AVAILABLE, 125 NotificationType::DEVICE_TOKEN_AVAILABLE,
112 NotificationService::AllSources()); 126 NotificationService::AllSources());
113 127
114 const FilePath policy_path = storage_dir_.Append( 128 const FilePath policy_path = storage_dir_.Append(
115 FILE_PATH_LITERAL("Policy")); 129 FILE_PATH_LITERAL("Policy"));
116 cache_.reset(new DeviceManagementPolicyCache(policy_path)); 130 cache_.reset(new DeviceManagementPolicyCache(policy_path));
117 cache_->LoadPolicyFromFile(); 131 cache_->LoadPolicyFromFile();
118 132
119 // Defer initialization that requires the IOThread until after the IOThread 133 // Defer initialization that requires the IOThread until after the IOThread
120 // has been initialized. 134 // has been initialized.
121 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 135 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
122 new InitializeAfterIOThreadExistsTask(AsWeakPtr())); 136 new InitializeAfterIOThreadExistsTask(AsWeakPtr()));
123 } 137 }
124 138
125 void DeviceManagementPolicyProvider::InitializeAfterIOThreadExists() { 139 void DeviceManagementPolicyProvider::InitializeAfterIOThreadExists() {
126 const FilePath token_path = storage_dir_.Append( 140 const FilePath token_path = storage_dir_.Append(
127 FILE_PATH_LITERAL("Token")); 141 FILE_PATH_LITERAL("Token"));
128 if (token_service_) { 142 if (profile_) {
129 token_fetcher_ = 143 if (!token_fetcher_) {
130 new DeviceTokenFetcher(backend_.get(), token_service_, token_path); 144 token_fetcher_ =
145 new DeviceTokenFetcher(backend_.get(), profile_, token_path);
146 }
131 token_fetcher_->StartFetching(); 147 token_fetcher_->StartFetching();
132 } 148 }
133 } 149 }
134 150
135 void DeviceManagementPolicyProvider::SendPolicyRequest() { 151 void DeviceManagementPolicyProvider::SendPolicyRequest() {
136 if (!policy_request_pending_) { 152 if (!policy_request_pending_) {
137 em::DevicePolicyRequest policy_request; 153 em::DevicePolicyRequest policy_request;
138 policy_request.set_policy_scope(kChromePolicyScope); 154 policy_request.set_policy_scope(kChromePolicyScope);
139 em::DevicePolicySettingRequest* setting = 155 em::DevicePolicySettingRequest* setting =
140 policy_request.add_setting_request(); 156 policy_request.add_setting_request();
(...skipping 27 matching lines...) Expand all
168 const FilePath device_management_dir = user_data_dir.Append( 184 const FilePath device_management_dir = user_data_dir.Append(
169 FILE_PATH_LITERAL("Device Management")); 185 FILE_PATH_LITERAL("Device Management"));
170 if (!file_util::DirectoryExists(device_management_dir)) { 186 if (!file_util::DirectoryExists(device_management_dir)) {
171 if (!file_util::CreateDirectory(device_management_dir)) 187 if (!file_util::CreateDirectory(device_management_dir))
172 NOTREACHED(); 188 NOTREACHED();
173 } 189 }
174 return device_management_dir; 190 return device_management_dir;
175 } 191 }
176 192
177 } // namespace policy 193 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698