version_info_updater.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_VERSION_INFO_UPDATER_H_ 6#define CHROME_BROWSER_CHROMEOS_LOGIN_VERSION_INFO_UPDATER_H_ 7 8#include <string> 9 10#include "base/memory/weak_ptr.h" 11#include "chrome/browser/chromeos/boot_times_loader.h" 12#include "chrome/browser/chromeos/version_loader.h" 13#include "chrome/browser/policy/cloud/cloud_policy_store.h" 14#include "content/public/browser/notification_observer.h" 15 16namespace chromeos { 17 18class CrosSettings; 19 20// Fetches all info we want to show on OOBE/Login screens about system 21// version, boot times and cloud policy. 22class VersionInfoUpdater : public policy::CloudPolicyStore::Observer, 23 public content::NotificationObserver { 24 public: 25 class Delegate { 26 public: 27 virtual ~Delegate() {} 28 29 // Called when OS version label should be updated. 30 virtual void OnOSVersionLabelTextUpdated( 31 const std::string& os_version_label_text) = 0; 32 33 // Called when boot times label should be updated. 34 virtual void OnBootTimesLabelTextUpdated( 35 const std::string& boot_times_label_text) = 0; 36 37 // Called when the enterprise info notice should be updated. 38 virtual void OnEnterpriseInfoUpdated( 39 const std::string& enterprise_info) = 0; 40 }; 41 42 explicit VersionInfoUpdater(Delegate* delegate); 43 virtual ~VersionInfoUpdater(); 44 45 // Sets delegate. 46 void set_delegate(Delegate* delegate) { delegate_ = delegate; } 47 48 // Starts fetching version info. The delegate will be notified when update 49 // is received. 50 void StartUpdate(bool is_official_build); 51 52 private: 53 // policy::CloudPolicyStore::Observer interface: 54 virtual void OnStoreLoaded(policy::CloudPolicyStore* store) OVERRIDE; 55 virtual void OnStoreError(policy::CloudPolicyStore* store) OVERRIDE; 56 57 // content::NotificationObserver interface. 58 virtual void Observe( 59 int type, 60 const content::NotificationSource& source, 61 const content::NotificationDetails& details) OVERRIDE; 62 63 // Update the version label. 64 void UpdateVersionLabel(); 65 66 // Check and update enterprise domain. 67 void UpdateEnterpriseInfo(); 68 69 // Set enterprise domain name. 70 void SetEnterpriseInfo(const std::string& domain_name); 71 72 // Callback from chromeos::VersionLoader giving the version. 73 void OnVersion(const std::string& version); 74 // Callback from chromeos::InfoLoader giving the boot times. 75 void OnBootTimes(const BootTimesLoader::BootTimes& boot_times); 76 // Null callback from chromeos::InfoLoader. 77 void OnBootTimesNoop(const BootTimesLoader::BootTimes& boot_times); 78 79 // Handles asynchronously loading the version. 80 VersionLoader version_loader_; 81 // Handles asynchronously loading the boot times. 82 BootTimesLoader boot_times_loader_; 83 // Used to request version and boot times. 84 CancelableTaskTracker tracker_; 85 86 // Information pieces for version label. 87 std::string version_text_; 88 89 // Full text for the OS version label. 90 std::string os_version_label_text_; 91 92 chromeos::CrosSettings* cros_settings_; 93 94 Delegate* delegate_; 95 96 // Weak pointer factory so we can give our callbacks for invocation 97 // at a later time without worrying that they will actually try to 98 // happen after the lifetime of this object. 99 base::WeakPtrFactory<VersionInfoUpdater> weak_pointer_factory_; 100 101 DISALLOW_COPY_AND_ASSIGN(VersionInfoUpdater); 102}; 103 104} // namespace chromeos 105 106#endif // CHROME_BROWSER_CHROMEOS_LOGIN_VERSION_INFO_UPDATER_H_ 107