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

Side by Side Diff: chrome/browser/ui/webui/settings/about_handler.cc

Issue 2925973002: Migrate upgrade notifications to observer (Closed)
Patch Set: Fix test failure Created 3 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/settings/about_handler.h" 5 #include "chrome/browser/ui/webui/settings/about_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "ash/system/devicetype_utils.h" 11 #include "ash/system/devicetype_utils.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/i18n/message_formatter.h" 17 #include "base/i18n/message_formatter.h"
18 #include "base/location.h" 18 #include "base/location.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "base/task_scheduler/post_task.h" 25 #include "base/task_scheduler/post_task.h"
26 #include "base/time/time.h" 26 #include "base/time/time.h"
27 #include "base/values.h" 27 #include "base/values.h"
28 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "chrome/browser/browser_process.h" 29 #include "chrome/browser/browser_process.h"
30 #include "chrome/browser/chrome_notification_types.h"
31 #include "chrome/browser/obsolete_system/obsolete_system.h" 30 #include "chrome/browser/obsolete_system/obsolete_system.h"
32 #include "chrome/browser/ui/browser.h" 31 #include "chrome/browser/ui/browser.h"
33 #include "chrome/browser/ui/browser_commands.h" 32 #include "chrome/browser/ui/browser_commands.h"
34 #include "chrome/browser/ui/browser_finder.h" 33 #include "chrome/browser/ui/browser_finder.h"
35 #include "chrome/browser/ui/chrome_pages.h" 34 #include "chrome/browser/ui/chrome_pages.h"
35 #include "chrome/browser/upgrade_detector.h"
36 #include "chrome/common/channel_info.h" 36 #include "chrome/common/channel_info.h"
37 #include "chrome/common/chrome_content_client.h" 37 #include "chrome/common/chrome_content_client.h"
38 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
39 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
40 #include "chrome/grit/chromium_strings.h" 40 #include "chrome/grit/chromium_strings.h"
41 #include "chrome/grit/generated_resources.h" 41 #include "chrome/grit/generated_resources.h"
42 #include "components/google/core/browser/google_util.h" 42 #include "components/google/core/browser/google_util.h"
43 #include "components/policy/core/common/policy_namespace.h" 43 #include "components/policy/core/common/policy_namespace.h"
44 #include "components/policy/policy_constants.h" 44 #include "components/policy/policy_constants.h"
45 #include "components/strings/grit/components_chromium_strings.h" 45 #include "components/strings/grit/components_chromium_strings.h"
46 #include "components/strings/grit/components_strings.h" 46 #include "components/strings/grit/components_strings.h"
47 #include "components/version_info/version_info.h" 47 #include "components/version_info/version_info.h"
48 #include "content/public/browser/browser_thread.h" 48 #include "content/public/browser/browser_thread.h"
49 #include "content/public/browser/notification_service.h"
50 #include "content/public/browser/web_contents.h" 49 #include "content/public/browser/web_contents.h"
51 #include "content/public/browser/web_ui.h" 50 #include "content/public/browser/web_ui.h"
52 #include "content/public/browser/web_ui_data_source.h" 51 #include "content/public/browser/web_ui_data_source.h"
53 #include "content/public/common/user_agent.h" 52 #include "content/public/common/user_agent.h"
54 #include "ui/base/l10n/l10n_util.h" 53 #include "ui/base/l10n/l10n_util.h"
55 #include "v8/include/v8-version-string.h" 54 #include "v8/include/v8-version-string.h"
56 55
57 #if defined(OS_CHROMEOS) 56 #if defined(OS_CHROMEOS)
58 #include "base/files/file_util_proxy.h" 57 #include "base/files/file_util_proxy.h"
59 #include "base/i18n/time_formatting.h" 58 #include "base/i18n/time_formatting.h"
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 378
380 #if defined(OS_CHROMEOS) 379 #if defined(OS_CHROMEOS)
381 // Handler for the product label image, which will be shown if available. 380 // Handler for the product label image, which will be shown if available.
382 content::URLDataSource::Add(Profile::FromWebUI(web_ui()), 381 content::URLDataSource::Add(Profile::FromWebUI(web_ui()),
383 new chromeos::ImageSource()); 382 new chromeos::ImageSource());
384 #endif 383 #endif
385 } 384 }
386 385
387 void AboutHandler::OnJavascriptAllowed() { 386 void AboutHandler::OnJavascriptAllowed() {
388 version_updater_.reset(VersionUpdater::Create(web_ui()->GetWebContents())); 387 version_updater_.reset(VersionUpdater::Create(web_ui()->GetWebContents()));
389 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 388 UpgradeDetector::GetInstance()->AddObserver(this);
390 content::NotificationService::AllSources());
391 policy_registrar_.reset(new policy::PolicyChangeRegistrar( 389 policy_registrar_.reset(new policy::PolicyChangeRegistrar(
392 g_browser_process->policy_service(), 390 g_browser_process->policy_service(),
393 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string()))); 391 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())));
394 policy_registrar_->Observe( 392 policy_registrar_->Observe(
395 policy::key::kDeviceAutoUpdateDisabled, 393 policy::key::kDeviceAutoUpdateDisabled,
396 base::Bind(&AboutHandler::OnDeviceAutoUpdatePolicyChanged, 394 base::Bind(&AboutHandler::OnDeviceAutoUpdatePolicyChanged,
397 base::Unretained(this))); 395 base::Unretained(this)));
398 } 396 }
399 397
400 void AboutHandler::OnJavascriptDisallowed() { 398 void AboutHandler::OnJavascriptDisallowed() {
sky 2017/06/07 23:01:42 Is there a guarantee that this is called before th
weidongg 2017/06/08 02:28:42 I am not sure, but I moved AddObserver and RemoveO
401 version_updater_.reset(); 399 version_updater_.reset();
402 policy_registrar_.reset(); 400 policy_registrar_.reset();
403 registrar_.Remove(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 401 UpgradeDetector::GetInstance()->RemoveObserver(this);
404 content::NotificationService::AllSources());
405 } 402 }
406 403
407 void AboutHandler::Observe(int type, 404 void AboutHandler::OnUpgradeRecommended() {
408 const content::NotificationSource& source,
409 const content::NotificationDetails& details) {
410 DCHECK_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, type);
411
412 // A version update is installed and ready to go. Refresh the UI so the 405 // A version update is installed and ready to go. Refresh the UI so the
413 // correct state will be shown. 406 // correct state will be shown.
414 RequestUpdate(); 407 RequestUpdate();
415 } 408 }
416 409
417 void AboutHandler::OnDeviceAutoUpdatePolicyChanged( 410 void AboutHandler::OnDeviceAutoUpdatePolicyChanged(
418 const base::Value* previous_policy, 411 const base::Value* previous_policy,
419 const base::Value* current_policy) { 412 const base::Value* current_policy) {
420 bool previous_auto_update_disabled = false; 413 bool previous_auto_update_disabled = false;
421 if (previous_policy) 414 if (previous_policy)
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 label_dir_path.AppendASCII(kRegulatoryLabelImageFilename).MaybeAsASCII(); 679 label_dir_path.AppendASCII(kRegulatoryLabelImageFilename).MaybeAsASCII();
687 std::string url = 680 std::string url =
688 std::string("chrome://") + chrome::kChromeOSAssetHost + "/" + image_path; 681 std::string("chrome://") + chrome::kChromeOSAssetHost + "/" + image_path;
689 regulatory_info->SetString("url", url); 682 regulatory_info->SetString("url", url);
690 683
691 ResolveJavascriptCallback(base::Value(callback_id), *regulatory_info); 684 ResolveJavascriptCallback(base::Value(callback_id), *regulatory_info);
692 } 685 }
693 #endif // defined(OS_CHROMEOS) 686 #endif // defined(OS_CHROMEOS)
694 687
695 } // namespace settings 688 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698