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

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

Issue 25690003: Refactored the DeviceManagementService to get its parameters from a delegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/policy/cloud/device_management_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser_policy_connector.h" 5 #include "chrome/browser/policy/browser_policy_connector.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return base::FilePath(); 115 return base::FilePath();
116 116
117 CFStringRef bundle_id = CFBundleGetIdentifier(bundle); 117 CFStringRef bundle_id = CFBundleGetIdentifier(bundle);
118 if (!bundle_id) 118 if (!bundle_id)
119 return base::FilePath(); 119 return base::FilePath();
120 120
121 return path.Append(base::SysCFStringRefToUTF8(bundle_id) + ".plist"); 121 return path.Append(base::SysCFStringRefToUTF8(bundle_id) + ".plist");
122 } 122 }
123 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 123 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
124 124
125 std::string GetDeviceManagementUrl() { 125 class DeviceManagementServiceConfiguration
126 CommandLine* command_line = CommandLine::ForCurrentProcess(); 126 : public DeviceManagementService::Configuration {
127 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) 127 public:
128 return command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl); 128 DeviceManagementServiceConfiguration() {}
129 else 129 virtual ~DeviceManagementServiceConfiguration() {}
130 return kDefaultDeviceManagementServerUrl;
131 }
132 130
133 std::string GetUserAgentParameter() { 131 virtual std::string GetServerUrl() OVERRIDE {
134 chrome::VersionInfo version_info; 132 CommandLine* command_line = CommandLine::ForCurrentProcess();
135 return base::StringPrintf("%s %s(%s)", 133 if (command_line->HasSwitch(switches::kDeviceManagementUrl))
136 version_info.Name().c_str(), 134 return command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl);
137 version_info.Version().c_str(), 135 else
138 version_info.LastChange().c_str()); 136 return kDefaultDeviceManagementServerUrl;
139 } 137 }
140 138
141 std::string GetPlatformParameter() { 139 virtual std::string GetUserAgent() OVERRIDE {
142 std::string os_name = base::SysInfo::OperatingSystemName(); 140 return content::GetUserAgent(GURL(GetServerUrl()));
143 std::string os_hardware = base::SysInfo::OperatingSystemArchitecture(); 141 }
142
143 virtual std::string GetAgentParameter() OVERRIDE {
144 chrome::VersionInfo version_info;
145 return base::StringPrintf("%s %s(%s)",
146 version_info.Name().c_str(),
147 version_info.Version().c_str(),
148 version_info.LastChange().c_str());
149 }
150
151 virtual std::string GetPlatformParameter() OVERRIDE {
152 std::string os_name = base::SysInfo::OperatingSystemName();
153 std::string os_hardware = base::SysInfo::OperatingSystemArchitecture();
144 154
145 #if defined(OS_CHROMEOS) 155 #if defined(OS_CHROMEOS)
146 chromeos::system::StatisticsProvider* provider = 156 chromeos::system::StatisticsProvider* provider =
147 chromeos::system::StatisticsProvider::GetInstance(); 157 chromeos::system::StatisticsProvider::GetInstance();
148 158
149 std::string hwclass; 159 std::string hwclass;
150 if (!provider->GetMachineStatistic(chromeos::system::kHardwareClass, 160 if (!provider->GetMachineStatistic(chromeos::system::kHardwareClass,
151 &hwclass)) { 161 &hwclass)) {
152 LOG(ERROR) << "Failed to get machine information"; 162 LOG(ERROR) << "Failed to get machine information";
153 } 163 }
154 os_name += ",CrOS," + base::SysInfo::GetLsbReleaseBoard(); 164 os_name += ",CrOS," + base::SysInfo::GetLsbReleaseBoard();
155 os_hardware += "," + hwclass; 165 os_hardware += "," + hwclass;
156 #endif 166 #endif
157 167
158 std::string os_version("-"); 168 std::string os_version("-");
159 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 169 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
160 int32 os_major_version = 0; 170 int32 os_major_version = 0;
161 int32 os_minor_version = 0; 171 int32 os_minor_version = 0;
162 int32 os_bugfix_version = 0; 172 int32 os_bugfix_version = 0;
163 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version, 173 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
164 &os_minor_version, 174 &os_minor_version,
165 &os_bugfix_version); 175 &os_bugfix_version);
166 os_version = base::StringPrintf("%d.%d.%d", 176 os_version = base::StringPrintf("%d.%d.%d",
167 os_major_version, 177 os_major_version,
168 os_minor_version, 178 os_minor_version,
169 os_bugfix_version); 179 os_bugfix_version);
170 #endif 180 #endif
171 181
172 return base::StringPrintf( 182 return base::StringPrintf(
173 "%s|%s|%s", os_name.c_str(), os_hardware.c_str(), os_version.c_str()); 183 "%s|%s|%s", os_name.c_str(), os_hardware.c_str(), os_version.c_str());
174 } 184 }
185 };
175 186
176 } // namespace 187 } // namespace
177 188
178 BrowserPolicyConnector::BrowserPolicyConnector() 189 BrowserPolicyConnector::BrowserPolicyConnector()
179 : is_initialized_(false), 190 : is_initialized_(false),
180 local_state_(NULL), 191 local_state_(NULL),
181 weak_ptr_factory_(this) { 192 weak_ptr_factory_(this) {
182 // GetPolicyService() must be ready after the constructor is done. 193 // GetPolicyService() must be ready after the constructor is done.
183 // The connector is created very early during startup, when the browser 194 // The connector is created very early during startup, when the browser
184 // threads aren't running yet; initialize components that need local_state, 195 // threads aren't running yet; initialize components that need local_state,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 PrefService* local_state, 240 PrefService* local_state,
230 scoped_refptr<net::URLRequestContextGetter> request_context) { 241 scoped_refptr<net::URLRequestContextGetter> request_context) {
231 // Initialization of some of the providers requires the FILE thread; make 242 // Initialization of some of the providers requires the FILE thread; make
232 // sure that threading is ready at this point. 243 // sure that threading is ready at this point.
233 DCHECK(BrowserThread::IsThreadInitialized(BrowserThread::FILE)); 244 DCHECK(BrowserThread::IsThreadInitialized(BrowserThread::FILE));
234 DCHECK(!is_initialized()) << "BrowserPolicyConnector::Init() called twice."; 245 DCHECK(!is_initialized()) << "BrowserPolicyConnector::Init() called twice.";
235 246
236 local_state_ = local_state; 247 local_state_ = local_state;
237 request_context_ = request_context; 248 request_context_ = request_context;
238 249
239 std::string server_url = GetDeviceManagementUrl(); 250 scoped_ptr<DeviceManagementService::Configuration> configuration(
251 new DeviceManagementServiceConfiguration);
240 device_management_service_.reset( 252 device_management_service_.reset(
241 new DeviceManagementService(request_context, 253 new DeviceManagementService(configuration.Pass(), request_context));
242 server_url,
243 content::GetUserAgent(GURL(server_url)),
244 GetUserAgentParameter(),
245 GetPlatformParameter()));
246 device_management_service_->ScheduleInitialization( 254 device_management_service_->ScheduleInitialization(
247 kServiceInitializationStartupDelay); 255 kServiceInitializationStartupDelay);
248 256
249 if (g_testing_provider) 257 if (g_testing_provider)
250 g_testing_provider->Init(); 258 g_testing_provider->Init();
251 if (platform_provider_) 259 if (platform_provider_)
252 platform_provider_->Init(); 260 platform_provider_->Init();
253 261
254 #if defined(OS_CHROMEOS) 262 #if defined(OS_CHROMEOS)
255 global_user_cloud_policy_provider_.Init(); 263 global_user_cloud_policy_provider_.Init();
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 return new AsyncPolicyProvider(loader.Pass()); 558 return new AsyncPolicyProvider(loader.Pass());
551 } else { 559 } else {
552 return NULL; 560 return NULL;
553 } 561 }
554 #else 562 #else
555 return NULL; 563 return NULL;
556 #endif 564 #endif
557 } 565 }
558 566
559 } // namespace policy 567 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/policy/cloud/device_management_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698