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