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

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

Issue 780203002: Fix threading bugs in product label UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: File path and ImageSource changes Created 6 years 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 29 matching lines...) Expand all
40 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
41 #include "v8/include/v8.h" 41 #include "v8/include/v8.h"
42 42
43 #if defined(OS_MACOSX) 43 #if defined(OS_MACOSX)
44 #include "chrome/browser/mac/obsolete_system.h" 44 #include "chrome/browser/mac/obsolete_system.h"
45 #endif 45 #endif
46 46
47 #if defined(OS_CHROMEOS) 47 #if defined(OS_CHROMEOS)
48 #include "base/files/file_util_proxy.h" 48 #include "base/files/file_util_proxy.h"
49 #include "base/i18n/time_formatting.h" 49 #include "base/i18n/time_formatting.h"
50 #include "base/path_service.h"
50 #include "base/prefs/pref_service.h" 51 #include "base/prefs/pref_service.h"
51 #include "base/sys_info.h" 52 #include "base/sys_info.h"
53 #include "base/task_runner_util.h"
52 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 54 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
53 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 55 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
54 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 56 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
55 #include "chrome/browser/chromeos/profiles/profile_helper.h" 57 #include "chrome/browser/chromeos/profiles/profile_helper.h"
56 #include "chrome/browser/chromeos/settings/cros_settings.h" 58 #include "chrome/browser/chromeos/settings/cros_settings.h"
57 #include "chrome/browser/profiles/profile.h" 59 #include "chrome/browser/profiles/profile.h"
58 #include "chrome/browser/ui/webui/chromeos/image_source.h" 60 #include "chrome/browser/ui/webui/chromeos/image_source.h"
59 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h" 61 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h"
60 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h" 62 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h"
63 #include "chromeos/chromeos_paths.h"
61 #include "chromeos/chromeos_switches.h" 64 #include "chromeos/chromeos_switches.h"
62 #include "chromeos/dbus/dbus_thread_manager.h" 65 #include "chromeos/dbus/dbus_thread_manager.h"
63 #include "chromeos/dbus/power_manager_client.h" 66 #include "chromeos/dbus/power_manager_client.h"
64 #include "components/user_manager/user_manager.h" 67 #include "components/user_manager/user_manager.h"
65 #endif 68 #endif
66 69
67 using base::ListValue; 70 using base::ListValue;
68 using content::BrowserThread; 71 using content::BrowserThread;
69 72
70 namespace { 73 namespace {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 chromeos::OwnerSettingsServiceChromeOSFactory::GetInstance() 122 chromeos::OwnerSettingsServiceChromeOSFactory::GetInstance()
120 ->GetForBrowserContext(profile); 123 ->GetForBrowserContext(profile);
121 // On non managed machines we have local owner who is the only one to change 124 // On non managed machines we have local owner who is the only one to change
122 // anything. Ensure that ReleaseChannelDelegated is false. 125 // anything. Ensure that ReleaseChannelDelegated is false.
123 if (service && service->IsOwner()) 126 if (service && service->IsOwner())
124 return !value; 127 return !value;
125 } 128 }
126 return false; 129 return false;
127 } 130 }
128 131
132 // Reads the file containing the FCC label text, if found.
133 std::string ReadFCCLabelText() {
134 base::FilePath shared_assets_dir;
135 std::string contents;
136 if (PathService::Get(chromeos::DIR_SHARED_ASSETS, &shared_assets_dir) &&
137 base::ReadFileToString(shared_assets_dir.AppendASCII(kFCCLabelTextPath),
138 &contents)) {
139 return contents;
140 }
141 return std::string();
142 }
143
129 #endif // defined(OS_CHROMEOS) 144 #endif // defined(OS_CHROMEOS)
130 145
131 } // namespace 146 } // namespace
132 147
133 HelpHandler::HelpHandler() 148 HelpHandler::HelpHandler()
134 : version_updater_(VersionUpdater::Create(nullptr)), weak_factory_(this) { 149 : version_updater_(VersionUpdater::Create(nullptr)), weak_factory_(this) {
135 } 150 }
136 151
137 HelpHandler::~HelpHandler() { 152 HelpHandler::~HelpHandler() {
138 } 153 }
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 "help.HelpPage.updateIsEnterpriseManaged", 411 "help.HelpPage.updateIsEnterpriseManaged",
397 base::FundamentalValue(IsEnterpriseManaged())); 412 base::FundamentalValue(IsEnterpriseManaged()));
398 // First argument to GetChannel() is a flag that indicates whether 413 // First argument to GetChannel() is a flag that indicates whether
399 // current channel should be returned (if true) or target channel 414 // current channel should be returned (if true) or target channel
400 // (otherwise). 415 // (otherwise).
401 version_updater_->GetChannel(true, 416 version_updater_->GetChannel(true,
402 base::Bind(&HelpHandler::OnCurrentChannel, weak_factory_.GetWeakPtr())); 417 base::Bind(&HelpHandler::OnCurrentChannel, weak_factory_.GetWeakPtr()));
403 version_updater_->GetChannel(false, 418 version_updater_->GetChannel(false,
404 base::Bind(&HelpHandler::OnTargetChannel, weak_factory_.GetWeakPtr())); 419 base::Bind(&HelpHandler::OnTargetChannel, weak_factory_.GetWeakPtr()));
405 420
406 BrowserThread::PostTask( 421 base::PostTaskAndReplyWithResult(
407 BrowserThread::FILE, FROM_HERE, 422 content::BrowserThread::GetBlockingPool(),
408 base::Bind(&HelpHandler::LoadFCCLabelText, weak_factory_.GetWeakPtr())); 423 FROM_HERE,
424 base::Bind(&ReadFCCLabelText),
425 base::Bind(&HelpHandler::OnFCCLabelTextRead,
426 weak_factory_.GetWeakPtr()));
409 #endif 427 #endif
410 } 428 }
411 429
412 #if defined(OS_MACOSX) 430 #if defined(OS_MACOSX)
413 void HelpHandler::PromoteUpdater(const base::ListValue* args) { 431 void HelpHandler::PromoteUpdater(const base::ListValue* args) {
414 version_updater_->PromoteUpdater(); 432 version_updater_->PromoteUpdater();
415 } 433 }
416 #endif 434 #endif
417 435
418 void HelpHandler::RelaunchNow(const base::ListValue* args) { 436 void HelpHandler::RelaunchNow(const base::ListValue* args) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 void HelpHandler::OnCurrentChannel(const std::string& channel) { 598 void HelpHandler::OnCurrentChannel(const std::string& channel) {
581 web_ui()->CallJavascriptFunction( 599 web_ui()->CallJavascriptFunction(
582 "help.HelpPage.updateCurrentChannel", base::StringValue(channel)); 600 "help.HelpPage.updateCurrentChannel", base::StringValue(channel));
583 } 601 }
584 602
585 void HelpHandler::OnTargetChannel(const std::string& channel) { 603 void HelpHandler::OnTargetChannel(const std::string& channel) {
586 web_ui()->CallJavascriptFunction( 604 web_ui()->CallJavascriptFunction(
587 "help.HelpPage.updateTargetChannel", base::StringValue(channel)); 605 "help.HelpPage.updateTargetChannel", base::StringValue(channel));
588 } 606 }
589 607
590 void HelpHandler::LoadFCCLabelText() { 608 void HelpHandler::OnFCCLabelTextRead(std::string text) {
591 base::FilePath path(std::string(chrome::kChromeOSAssetPath) + 609 // Remove unnecessary whitespace.
592 kFCCLabelTextPath); 610 text = base::CollapseWhitespaceASCII(text, true);
593 std::string contents; 611 if (text.empty())
594 if (base::ReadFileToString(path, &contents)) { 612 return;
595 // Remove unnecessary whitespace. 613 base::StringValue label(text);
596 base::StringValue label(base::CollapseWhitespaceASCII(contents, true)); 614 web_ui()->CallJavascriptFunction("help.HelpPage.setProductLabelText", label);
597 web_ui()->CallJavascriptFunction("help.HelpPage.setProductLabelText",
598 label);
599 }
600 } 615 }
601 616
602 #endif // defined(OS_CHROMEOS) 617 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698