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

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

Issue 7298012: Consolidate data storage and notifications in the cloud policy subsystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 5 months 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) 2011 The Chromium Authors. All rights reserved. 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 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/cloud_policy_subsystem.h" 5 #include "chrome/browser/policy/cloud_policy_subsystem.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/policy/cloud_policy_cache_base.h" 12 #include "chrome/browser/policy/cloud_policy_cache_base.h"
13 #include "chrome/browser/policy/cloud_policy_controller.h" 13 #include "chrome/browser/policy/cloud_policy_controller.h"
14 #include "chrome/browser/policy/cloud_policy_identity_strategy.h" 14 #include "chrome/browser/policy/cloud_policy_data_store.h"
15 #include "chrome/browser/policy/device_management_service.h" 15 #include "chrome/browser/policy/device_management_service.h"
16 #include "chrome/browser/policy/device_token_fetcher.h" 16 #include "chrome/browser/policy/device_token_fetcher.h"
17 #include "chrome/browser/policy/policy_notifier.h" 17 #include "chrome/browser/policy/policy_notifier.h"
18 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "content/common/notification_details.h" 21 #include "content/common/notification_details.h"
22 #include "content/common/notification_source.h" 22 #include "content/common/notification_source.h"
23 #include "content/common/notification_type.h" 23 #include "content/common/notification_type.h"
24 24
(...skipping 17 matching lines...) Expand all
42 policy_notifier_ = cloud_policy_subsystem->notifier(); 42 policy_notifier_ = cloud_policy_subsystem->notifier();
43 policy_notifier_->AddObserver(observer); 43 policy_notifier_->AddObserver(observer);
44 } 44 }
45 45
46 CloudPolicySubsystem::ObserverRegistrar::~ObserverRegistrar() { 46 CloudPolicySubsystem::ObserverRegistrar::~ObserverRegistrar() {
47 if (policy_notifier_) 47 if (policy_notifier_)
48 policy_notifier_->RemoveObserver(observer_); 48 policy_notifier_->RemoveObserver(observer_);
49 } 49 }
50 50
51 CloudPolicySubsystem::CloudPolicySubsystem( 51 CloudPolicySubsystem::CloudPolicySubsystem(
52 CloudPolicyIdentityStrategy* identity_strategy, 52 CloudPolicyDataStore* data_store,
53 CloudPolicyCacheBase* policy_cache) { 53 CloudPolicyCacheBase* policy_cache) {
54 std::string device_management_url; 54 std::string device_management_url;
55 CommandLine* command_line = CommandLine::ForCurrentProcess(); 55 CommandLine* command_line = CommandLine::ForCurrentProcess();
56 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { 56 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
57 device_management_url = 57 device_management_url =
58 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl); 58 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl);
59 } 59 }
60 Initialize(identity_strategy, policy_cache, device_management_url); 60 Initialize(data_store, policy_cache, device_management_url);
61 } 61 }
62 62
63 CloudPolicySubsystem::~CloudPolicySubsystem() { 63 CloudPolicySubsystem::~CloudPolicySubsystem() {
64 cloud_policy_controller_.reset(); 64 cloud_policy_controller_.reset();
65 device_token_fetcher_.reset(); 65 device_token_fetcher_.reset();
66 cloud_policy_cache_.reset(); 66 cloud_policy_cache_.reset();
67 device_management_service_.reset(); 67 device_management_service_.reset();
68 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 68 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
69 } 69 }
70 70
71 void CloudPolicySubsystem::OnIPAddressChanged() { 71 void CloudPolicySubsystem::OnIPAddressChanged() {
72 if (state() == CloudPolicySubsystem::NETWORK_ERROR && 72 if (state() == CloudPolicySubsystem::NETWORK_ERROR &&
73 cloud_policy_controller_.get()) { 73 cloud_policy_controller_.get()) {
74 cloud_policy_controller_->Retry(); 74 cloud_policy_controller_->Retry();
75 } 75 }
76 } 76 }
77 77
78 void CloudPolicySubsystem::Initialize( 78 void CloudPolicySubsystem::Initialize(
79 CloudPolicyIdentityStrategy* identity_strategy, 79 CloudPolicyDataStore* data_store,
80 CloudPolicyCacheBase* policy_cache, 80 CloudPolicyCacheBase* policy_cache,
81 const std::string& device_management_url) { 81 const std::string& device_management_url) {
82 device_management_url_ = device_management_url; 82 device_management_url_ = device_management_url;
83 identity_strategy_ = identity_strategy; 83 data_store_ = data_store;
84 net::NetworkChangeNotifier::AddIPAddressObserver(this); 84 net::NetworkChangeNotifier::AddIPAddressObserver(this);
85 notifier_.reset(new PolicyNotifier()); 85 notifier_.reset(new PolicyNotifier());
86 if (!device_management_url_.empty()) { 86 if (!device_management_url_.empty()) {
87 device_management_service_.reset(new DeviceManagementService( 87 device_management_service_.reset(new DeviceManagementService(
88 device_management_url)); 88 device_management_url));
89 cloud_policy_cache_.reset(policy_cache); 89 cloud_policy_cache_.reset(policy_cache);
90 cloud_policy_cache_->set_policy_notifier(notifier_.get()); 90 cloud_policy_cache_->set_policy_notifier(notifier_.get());
91 cloud_policy_cache_->Load(); 91 cloud_policy_cache_->Load();
92 CreateDeviceTokenFetcher(); 92 CreateDeviceTokenFetcher();
93 } 93 }
94 } 94 }
95 95
96 void CloudPolicySubsystem::CompleteInitialization( 96 void CloudPolicySubsystem::CompleteInitialization(
97 const char* refresh_pref_name, 97 const char* refresh_pref_name,
98 int64 delay_milliseconds) { 98 int64 delay_milliseconds) {
99 if (!device_management_url_.empty()) { 99 if (!device_management_url_.empty()) {
100 DCHECK(device_management_service_.get()); 100 DCHECK(device_management_service_.get());
101 DCHECK(cloud_policy_cache_.get()); 101 DCHECK(cloud_policy_cache_.get());
102 DCHECK(device_token_fetcher_.get()); 102 DCHECK(device_token_fetcher_.get());
103 DCHECK(identity_strategy_);
104 103
105 refresh_pref_name_ = refresh_pref_name; 104 refresh_pref_name_ = refresh_pref_name;
106 CreateCloudPolicyController(); 105 CreateCloudPolicyController();
107 device_management_service_->ScheduleInitialization(delay_milliseconds); 106 device_management_service_->ScheduleInitialization(delay_milliseconds);
108 107
109 PrefService* local_state = g_browser_process->local_state(); 108 PrefService* local_state = g_browser_process->local_state();
110 DCHECK(pref_change_registrar_.IsEmpty()); 109 DCHECK(pref_change_registrar_.IsEmpty());
111 pref_change_registrar_.Init(local_state); 110 pref_change_registrar_.Init(local_state);
112 pref_change_registrar_.Add(refresh_pref_name_, this); 111 pref_change_registrar_.Add(refresh_pref_name_, this);
113 UpdatePolicyRefreshRate(local_state->GetInteger(refresh_pref_name_)); 112 UpdatePolicyRefreshRate(local_state->GetInteger(refresh_pref_name_));
(...skipping 12 matching lines...) Expand all
126 return notifier_->state(); 125 return notifier_->state();
127 } 126 }
128 127
129 CloudPolicySubsystem::ErrorDetails CloudPolicySubsystem::error_details() { 128 CloudPolicySubsystem::ErrorDetails CloudPolicySubsystem::error_details() {
130 return notifier_->error_details(); 129 return notifier_->error_details();
131 } 130 }
132 131
133 void CloudPolicySubsystem::StopAutoRetry() { 132 void CloudPolicySubsystem::StopAutoRetry() {
134 cloud_policy_controller_->StopAutoRetry(); 133 cloud_policy_controller_->StopAutoRetry();
135 device_token_fetcher_->StopAutoRetry(); 134 device_token_fetcher_->StopAutoRetry();
135 data_store_->Reset();
136 } 136 }
137 137
138 // static 138 // static
139 void CloudPolicySubsystem::RegisterPrefs(PrefService* pref_service) { 139 void CloudPolicySubsystem::RegisterPrefs(PrefService* pref_service) {
140 pref_service->RegisterIntegerPref(prefs::kDevicePolicyRefreshRate, 140 pref_service->RegisterIntegerPref(prefs::kDevicePolicyRefreshRate,
141 kDefaultPolicyRefreshRateMs, 141 kDefaultPolicyRefreshRateMs,
142 PrefService::UNSYNCABLE_PREF); 142 PrefService::UNSYNCABLE_PREF);
143 pref_service->RegisterIntegerPref(prefs::kUserPolicyRefreshRate, 143 pref_service->RegisterIntegerPref(prefs::kUserPolicyRefreshRate,
144 kDefaultPolicyRefreshRateMs, 144 kDefaultPolicyRefreshRateMs,
145 PrefService::UNSYNCABLE_PREF); 145 PrefService::UNSYNCABLE_PREF);
(...skipping 26 matching lines...) Expand all
172 int64 delay_milliseconds) { 172 int64 delay_milliseconds) {
173 if (device_management_service_.get()) 173 if (device_management_service_.get())
174 device_management_service_->ScheduleInitialization(delay_milliseconds); 174 device_management_service_->ScheduleInitialization(delay_milliseconds);
175 } 175 }
176 176
177 177
178 void CloudPolicySubsystem::CreateDeviceTokenFetcher() { 178 void CloudPolicySubsystem::CreateDeviceTokenFetcher() {
179 device_token_fetcher_.reset( 179 device_token_fetcher_.reset(
180 new DeviceTokenFetcher(device_management_service_.get(), 180 new DeviceTokenFetcher(device_management_service_.get(),
181 cloud_policy_cache_.get(), 181 cloud_policy_cache_.get(),
182 data_store_,
182 notifier_.get())); 183 notifier_.get()));
183 } 184 }
184 185
185 void CloudPolicySubsystem::CreateCloudPolicyController() { 186 void CloudPolicySubsystem::CreateCloudPolicyController() {
186 DCHECK(!cloud_policy_controller_.get()); 187 DCHECK(!cloud_policy_controller_.get());
187 cloud_policy_controller_.reset( 188 cloud_policy_controller_.reset(
188 new CloudPolicyController(device_management_service_.get(), 189 new CloudPolicyController(device_management_service_.get(),
189 cloud_policy_cache_.get(), 190 cloud_policy_cache_.get(),
190 device_token_fetcher_.get(), 191 device_token_fetcher_.get(),
191 identity_strategy_, 192 data_store_,
192 notifier_.get())); 193 notifier_.get()));
193 } 194 }
194 195
195 CloudPolicySubsystem::CloudPolicySubsystem() 196 CloudPolicySubsystem::CloudPolicySubsystem()
196 : refresh_pref_name_(NULL), 197 : refresh_pref_name_(NULL) {}
197 identity_strategy_(NULL) {
198 }
199 198
200 } // namespace policy 199 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_subsystem.h ('k') | chrome/browser/policy/cloud_policy_subsystem_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698