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

Side by Side Diff: chrome/browser/ui/webui/help/help_handler.cc

Issue 738843002: Call to CrosSettings::Set() is replaced by OwnerSettingsService::Set() in VersionUpdaterCros. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed non-chromeos builds. Created 6 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
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/ui/webui/help/help_handler.h" 5 #include "chrome/browser/ui/webui/help/help_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 30 matching lines...) Expand all
41 41
42 #if defined(OS_MACOSX) 42 #if defined(OS_MACOSX)
43 #include "chrome/browser/mac/obsolete_system.h" 43 #include "chrome/browser/mac/obsolete_system.h"
44 #endif 44 #endif
45 45
46 #if defined(OS_CHROMEOS) 46 #if defined(OS_CHROMEOS)
47 #include "base/files/file_util_proxy.h" 47 #include "base/files/file_util_proxy.h"
48 #include "base/i18n/time_formatting.h" 48 #include "base/i18n/time_formatting.h"
49 #include "base/prefs/pref_service.h" 49 #include "base/prefs/pref_service.h"
50 #include "base/sys_info.h" 50 #include "base/sys_info.h"
51 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
52 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
51 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 53 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
54 #include "chrome/browser/chromeos/profiles/profile_helper.h"
52 #include "chrome/browser/chromeos/settings/cros_settings.h" 55 #include "chrome/browser/chromeos/settings/cros_settings.h"
53 #include "chrome/browser/profiles/profile.h" 56 #include "chrome/browser/profiles/profile.h"
54 #include "chrome/browser/ui/webui/chromeos/image_source.h" 57 #include "chrome/browser/ui/webui/chromeos/image_source.h"
55 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h" 58 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h"
56 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h" 59 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h"
57 #include "chromeos/chromeos_switches.h" 60 #include "chromeos/chromeos_switches.h"
58 #include "chromeos/dbus/dbus_thread_manager.h" 61 #include "chromeos/dbus/dbus_thread_manager.h"
59 #include "chromeos/dbus/power_manager_client.h" 62 #include "chromeos/dbus/power_manager_client.h"
60 #include "components/user_manager/user_manager.h" 63 #include "components/user_manager/user_manager.h"
61 #endif 64 #endif
(...skipping 19 matching lines...) Expand all
81 } 84 }
82 85
83 // Returns true if the device is enterprise managed, false otherwise. 86 // Returns true if the device is enterprise managed, false otherwise.
84 bool IsEnterpriseManaged() { 87 bool IsEnterpriseManaged() {
85 policy::BrowserPolicyConnectorChromeOS* connector = 88 policy::BrowserPolicyConnectorChromeOS* connector =
86 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 89 g_browser_process->platform_part()->browser_policy_connector_chromeos();
87 return connector->IsEnterpriseManaged(); 90 return connector->IsEnterpriseManaged();
88 } 91 }
89 92
90 // Returns true if current user can change channel, false otherwise. 93 // Returns true if current user can change channel, false otherwise.
91 bool CanChangeChannel() { 94 bool CanChangeChannel(Profile* profile) {
92 bool value = false; 95 bool value = false;
93 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kReleaseChannelDelegated, 96 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kReleaseChannelDelegated,
94 &value); 97 &value);
95 98
96 // On a managed machine we delegate this setting to the users of the same 99 // On a managed machine we delegate this setting to the users of the same
97 // domain only if the policy value is "domain". 100 // domain only if the policy value is "domain".
98 if (IsEnterpriseManaged()) { 101 if (IsEnterpriseManaged()) {
99 if (!value) 102 if (!value)
100 return false; 103 return false;
101 // Get the currently logged in user and strip the domain part only. 104 // Get the currently logged in user and strip the domain part only.
102 std::string domain = ""; 105 std::string domain = "";
103 std::string user = 106 const user_manager::User* user =
104 user_manager::UserManager::Get()->GetLoggedInUser()->email(); 107 profile ? chromeos::ProfileHelper::Get()->GetUserByProfile(profile)
105 size_t at_pos = user.find('@'); 108 : nullptr;
106 if (at_pos != std::string::npos && at_pos + 1 < user.length()) 109 std::string email = user ? user->email() : std::string();
107 domain = user.substr(user.find('@') + 1); 110 size_t at_pos = email.find('@');
111 if (at_pos != std::string::npos && at_pos + 1 < email.length())
112 domain = email.substr(email.find('@') + 1);
108 policy::BrowserPolicyConnectorChromeOS* connector = 113 policy::BrowserPolicyConnectorChromeOS* connector =
109 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 114 g_browser_process->platform_part()->browser_policy_connector_chromeos();
110 return domain == connector->GetEnterpriseDomain(); 115 return domain == connector->GetEnterpriseDomain();
111 } else if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { 116 } else {
117 chromeos::OwnerSettingsServiceChromeOS* service =
118 chromeos::OwnerSettingsServiceChromeOSFactory::GetInstance()
119 ->GetForProfile(profile);
112 // On non managed machines we have local owner who is the only one to change 120 // On non managed machines we have local owner who is the only one to change
113 // anything. Ensure that ReleaseChannelDelegated is false. 121 // anything. Ensure that ReleaseChannelDelegated is false.
114 return !value; 122 if (service && service->IsOwner())
123 return !value;
115 } 124 }
116 return false; 125 return false;
117 } 126 }
118 127
119 #endif // defined(OS_CHROMEOS) 128 #endif // defined(OS_CHROMEOS)
120 129
121 } // namespace 130 } // namespace
122 131
123 HelpHandler::HelpHandler() 132 HelpHandler::HelpHandler()
124 : version_updater_(VersionUpdater::Create()), 133 : version_updater_(VersionUpdater::Create(nullptr)), weak_factory_(this) {
125 weak_factory_(this) {
126 } 134 }
127 135
128 HelpHandler::~HelpHandler() { 136 HelpHandler::~HelpHandler() {
129 } 137 }
130 138
131 void HelpHandler::GetLocalizedValues(base::DictionaryValue* localized_strings) { 139 void HelpHandler::GetLocalizedValues(base::DictionaryValue* localized_strings) {
132 struct L10nResources { 140 struct L10nResources {
133 const char* name; 141 const char* name;
134 int ids; 142 int ids;
135 }; 143 };
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 localized_strings->SetString("jsEngineVersion", v8::V8::GetVersion()); 277 localized_strings->SetString("jsEngineVersion", v8::V8::GetVersion());
270 278
271 localized_strings->SetString("userAgentInfo", GetUserAgent()); 279 localized_strings->SetString("userAgentInfo", GetUserAgent());
272 280
273 CommandLine::StringType command_line = 281 CommandLine::StringType command_line =
274 CommandLine::ForCurrentProcess()->GetCommandLineString(); 282 CommandLine::ForCurrentProcess()->GetCommandLineString();
275 localized_strings->SetString("commandLineInfo", command_line); 283 localized_strings->SetString("commandLineInfo", command_line);
276 } 284 }
277 285
278 void HelpHandler::RegisterMessages() { 286 void HelpHandler::RegisterMessages() {
287 #if defined(OS_CHROMEOS)
288 version_updater_.reset(VersionUpdater::Create(Profile::FromWebUI(web_ui())));
Nikita (slow) 2014/11/19 17:45:59 VersionUpdater::Create(web_ui()->GetWebContents()-
ygorshenin1 2014/11/19 18:30:44 Done.
289 #endif
279 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 290 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
280 content::NotificationService::AllSources()); 291 content::NotificationService::AllSources());
281 292
282 web_ui()->RegisterMessageCallback("onPageLoaded", 293 web_ui()->RegisterMessageCallback("onPageLoaded",
283 base::Bind(&HelpHandler::OnPageLoaded, base::Unretained(this))); 294 base::Bind(&HelpHandler::OnPageLoaded, base::Unretained(this)));
284 web_ui()->RegisterMessageCallback("relaunchNow", 295 web_ui()->RegisterMessageCallback("relaunchNow",
285 base::Bind(&HelpHandler::RelaunchNow, base::Unretained(this))); 296 base::Bind(&HelpHandler::RelaunchNow, base::Unretained(this)));
286 web_ui()->RegisterMessageCallback("openFeedbackDialog", 297 web_ui()->RegisterMessageCallback("openFeedbackDialog",
287 base::Bind(&HelpHandler::OpenFeedbackDialog, base::Unretained(this))); 298 base::Bind(&HelpHandler::OpenFeedbackDialog, base::Unretained(this)));
288 web_ui()->RegisterMessageCallback("openHelpPage", 299 web_ui()->RegisterMessageCallback("openHelpPage",
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 loader_.GetVersion( 355 loader_.GetVersion(
345 chromeos::VersionLoader::VERSION_FULL, 356 chromeos::VersionLoader::VERSION_FULL,
346 base::Bind(&HelpHandler::OnOSVersion, base::Unretained(this)), 357 base::Bind(&HelpHandler::OnOSVersion, base::Unretained(this)),
347 &tracker_); 358 &tracker_);
348 loader_.GetFirmware( 359 loader_.GetFirmware(
349 base::Bind(&HelpHandler::OnOSFirmware, base::Unretained(this)), 360 base::Bind(&HelpHandler::OnOSFirmware, base::Unretained(this)),
350 &tracker_); 361 &tracker_);
351 362
352 web_ui()->CallJavascriptFunction( 363 web_ui()->CallJavascriptFunction(
353 "help.HelpPage.updateEnableReleaseChannel", 364 "help.HelpPage.updateEnableReleaseChannel",
354 base::FundamentalValue(CanChangeChannel())); 365 base::FundamentalValue(CanChangeChannel(Profile::FromWebUI(web_ui()))));
355 366
356 base::Time build_time = base::SysInfo::GetLsbReleaseTime(); 367 base::Time build_time = base::SysInfo::GetLsbReleaseTime();
357 base::string16 build_date = base::TimeFormatFriendlyDate(build_time); 368 base::string16 build_date = base::TimeFormatFriendlyDate(build_time);
358 web_ui()->CallJavascriptFunction("help.HelpPage.setBuildDate", 369 web_ui()->CallJavascriptFunction("help.HelpPage.setBuildDate",
359 base::StringValue(build_date)); 370 base::StringValue(build_date));
360 #endif // defined(OS_CHROMEOS) 371 #endif // defined(OS_CHROMEOS)
361 372
362 // On Chrome OS, do not check for an update automatically. 373 // On Chrome OS, do not check for an update automatically.
363 #if defined(OS_CHROMEOS) 374 #if defined(OS_CHROMEOS)
364 static_cast<VersionUpdaterCros*>(version_updater_.get())->GetUpdateStatus( 375 static_cast<VersionUpdaterCros*>(version_updater_.get())->GetUpdateStatus(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 Browser* browser = chrome::FindBrowserWithWebContents( 430 Browser* browser = chrome::FindBrowserWithWebContents(
420 web_ui()->GetWebContents()); 431 web_ui()->GetWebContents());
421 chrome::ShowHelp(browser, chrome::HELP_SOURCE_WEBUI); 432 chrome::ShowHelp(browser, chrome::HELP_SOURCE_WEBUI);
422 } 433 }
423 434
424 #if defined(OS_CHROMEOS) 435 #if defined(OS_CHROMEOS)
425 436
426 void HelpHandler::SetChannel(const base::ListValue* args) { 437 void HelpHandler::SetChannel(const base::ListValue* args) {
427 DCHECK(args->GetSize() == 2); 438 DCHECK(args->GetSize() == 2);
428 439
429 if (!CanChangeChannel()) { 440 if (!CanChangeChannel(Profile::FromWebUI(web_ui()))) {
430 LOG(WARNING) << "Non-owner tried to change release track."; 441 LOG(WARNING) << "Non-owner tried to change release track.";
431 return; 442 return;
432 } 443 }
433 444
434 base::string16 channel; 445 base::string16 channel;
435 bool is_powerwash_allowed; 446 bool is_powerwash_allowed;
436 if (!args->GetString(0, &channel) || 447 if (!args->GetString(0, &channel) ||
437 !args->GetBoolean(1, &is_powerwash_allowed)) { 448 !args->GetBoolean(1, &is_powerwash_allowed)) {
438 LOG(ERROR) << "Can't parse SetChannel() args"; 449 LOG(ERROR) << "Can't parse SetChannel() args";
439 return; 450 return;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 std::string contents; 591 std::string contents;
581 if (base::ReadFileToString(path, &contents)) { 592 if (base::ReadFileToString(path, &contents)) {
582 // Remove unnecessary whitespace. 593 // Remove unnecessary whitespace.
583 base::StringValue label(base::CollapseWhitespaceASCII(contents, true)); 594 base::StringValue label(base::CollapseWhitespaceASCII(contents, true));
584 web_ui()->CallJavascriptFunction("help.HelpPage.setProductLabelText", 595 web_ui()->CallJavascriptFunction("help.HelpPage.setProductLabelText",
585 label); 596 label);
586 } 597 }
587 } 598 }
588 599
589 #endif // defined(OS_CHROMEOS) 600 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698