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 16 namespace chromeos { 17 18 class CrosSettings; 19 20 // Fetches all info we want to show on OOBE/Login screens about system 21 // version, boot times and cloud policy. 22 class 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 the enterprise info notice should be updated. 34 virtual void OnEnterpriseInfoUpdated( 35 const std::string& enterprise_info) = 0; 36 }; 37 38 explicit VersionInfoUpdater(Delegate* delegate); 39 virtual ~VersionInfoUpdater(); 40 41 // Sets delegate. 42 void set_delegate(Delegate* delegate) { delegate_ = delegate; } 43 44 // Starts fetching version info. The delegate will be notified when update 45 // is received. 46 void StartUpdate(bool is_official_build); 47 48 private: 49 // policy::CloudPolicyStore::Observer interface: 50 virtual void OnStoreLoaded(policy::CloudPolicyStore* store) OVERRIDE; 51 virtual void OnStoreError(policy::CloudPolicyStore* store) OVERRIDE; 52 53 // content::NotificationObserver interface. 54 virtual void Observe( 55 int type, 56 const content::NotificationSource& source, 57 const content::NotificationDetails& details) OVERRIDE; 58 59 // Update the version label. 60 void UpdateVersionLabel(); 61 62 // Check and update enterprise domain. 63 void UpdateEnterpriseInfo(); 64 65 // Set enterprise domain name. 66 void SetEnterpriseInfo(const std::string& domain_name); 67 68 // Callback from chromeos::VersionLoader giving the version. 69 void OnVersion(const std::string& version); 70 71 // Handles asynchronously loading the version. 72 VersionLoader version_loader_; 73 // Handles asynchronously loading the boot times. 74 BootTimesLoader boot_times_loader_; 75 // Used to request version and boot times. 76 CancelableTaskTracker tracker_; 77 78 // Information pieces for version label. 79 std::string version_text_; 80 81 // Full text for the OS version label. 82 std::string os_version_label_text_; 83 84 chromeos::CrosSettings* cros_settings_; 85 86 Delegate* delegate_; 87 88 // Weak pointer factory so we can give our callbacks for invocation 89 // at a later time without worrying that they will actually try to 90 // happen after the lifetime of this object. 91 base::WeakPtrFactory<VersionInfoUpdater> weak_pointer_factory_; 92 93 DISALLOW_COPY_AND_ASSIGN(VersionInfoUpdater); 94 }; 95 96 } // namespace chromeos 97 98 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_VERSION_INFO_UPDATER_H_ 99