summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/locale_change_guard.h
blob: ed6fa430d947df01f8dafa0b36c1a0618fbdc55a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_
#define CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_
#pragma once

#include "base/lazy_instance.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/chromeos/notifications/system_notification.h"
#include "chrome/browser/notifications/notification_delegate.h"
#include "chrome/browser/profiles/profile.h"

class ListValue;
class TabContents;

namespace chromeos {

class LocaleChangeGuard {
 public:
  // When called first time for user profile: performs check whether
  // locale has been changed automatically recently (based on synchronized user
  // preference).  If so: shows notification that allows user to revert change.
  // On subsequent calls: does nothing (hopefully fast).
  static void Check(TabContents* tab_contents);

 private:
  class Delegate : public NotificationDelegate {
   public:
    explicit Delegate(chromeos::LocaleChangeGuard* master) : master_(master) {}
    void Close(bool by_user);
    void Display() {}
    void Error() {}
    void Click() {}
    std::string id() const;

   private:
    chromeos::LocaleChangeGuard* master_;

    DISALLOW_COPY_AND_ASSIGN(Delegate);
  };

  LocaleChangeGuard();
  void CheckLocaleChange(TabContents* tab_contents);
  void RevertLocaleChange(const ListValue* list);
  void AcceptLocaleChange();

  std::string from_locale_;
  std::string to_locale_;
  ProfileId profile_id_;
  TabContents* tab_contents_;
  scoped_ptr<chromeos::SystemNotification> note_;
  bool reverted_;

  friend struct base::DefaultLazyInstanceTraits<LocaleChangeGuard>;
};

}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_