Home | History | Annotate | Download | only in chromeos
      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_LOCALE_CHANGE_GUARD_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_
      7 
      8 #include <string>
      9 
     10 #include "ash/system/locale/locale_observer.h"
     11 #include "base/compiler_specific.h"
     12 #include "base/lazy_instance.h"
     13 #include "base/memory/scoped_ptr.h"
     14 #include "base/memory/weak_ptr.h"
     15 #include "base/strings/string16.h"
     16 #include "content/public/browser/notification_observer.h"
     17 #include "content/public/browser/notification_registrar.h"
     18 #include "content/public/browser/notification_types.h"
     19 
     20 class Profile;
     21 
     22 namespace base {
     23 class ListValue;
     24 }
     25 
     26 namespace chromeos {
     27 
     28 // Performs check whether locale has been changed automatically recently
     29 // (based on synchronized user preference).  If so: shows notification that
     30 // allows user to revert change.
     31 class LocaleChangeGuard : public content::NotificationObserver,
     32                           public ash::LocaleObserver::Delegate,
     33                           public base::SupportsWeakPtr<LocaleChangeGuard> {
     34  public:
     35   explicit LocaleChangeGuard(Profile* profile);
     36   virtual ~LocaleChangeGuard();
     37 
     38   // ash::LocaleChangeDelegate implementation.
     39   virtual void AcceptLocaleChange() OVERRIDE;
     40   virtual void RevertLocaleChange() OVERRIDE;
     41 
     42   // Called just before changing locale.
     43   void PrepareChangingLocale(
     44       const std::string& from_locale, const std::string& to_locale);
     45 
     46   // Called after login.
     47   void OnLogin();
     48 
     49  private:
     50   void RevertLocaleChangeCallback(const base::ListValue* list);
     51   void Check();
     52 
     53   // content::NotificationObserver implementation.
     54   virtual void Observe(int type,
     55                        const content::NotificationSource& source,
     56                        const content::NotificationDetails& details) OVERRIDE;
     57 
     58   std::string from_locale_;
     59   std::string to_locale_;
     60   Profile* profile_;
     61   bool reverted_;
     62   bool session_started_;
     63   bool main_frame_loaded_;
     64   content::NotificationRegistrar registrar_;
     65 
     66   // We want to show locale change notification in previous language however
     67   // we cannot directly load strings for non-current locale.  So we cache
     68   // messages before locale change.
     69   base::string16 title_text_;
     70   base::string16 message_text_;
     71   base::string16 revert_link_text_;
     72 };
     73 
     74 }  // namespace chromeos
     75 
     76 #endif  // CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_
     77