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

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

Powered by Google App Engine
This is Rietveld 408576698