OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/app_notify_channel_ui_impl.h" | 5 #include "chrome/browser/extensions/app_notify_channel_ui_impl.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 8 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
9 #include "chrome/browser/api/infobars/infobar_service.h" | 9 #include "chrome/browser/api/infobars/infobar_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
29 | 29 |
30 namespace extensions { | 30 namespace extensions { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 class AppNotifyChannelUIInfoBarDelegate : public ConfirmInfoBarDelegate { | 34 class AppNotifyChannelUIInfoBarDelegate : public ConfirmInfoBarDelegate { |
35 public: | 35 public: |
36 AppNotifyChannelUIInfoBarDelegate(AppNotifyChannelUIImpl* creator, | 36 // Creates an app notify channel UI delegate and adds it to |infobar_service|. |
37 InfoBarService* infobar_service, | 37 static void Create(InfoBarService* infobar_service, |
38 const std::string& app_name); | 38 AppNotifyChannelUIImpl* creator, |
39 virtual ~AppNotifyChannelUIInfoBarDelegate(); | 39 const std::string& app_name); |
40 | 40 |
41 // ConfirmInfoBarDelegate. | 41 // ConfirmInfoBarDelegate. |
42 virtual string16 GetMessageText() const OVERRIDE; | 42 virtual string16 GetMessageText() const OVERRIDE; |
43 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 43 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
44 virtual bool Accept() OVERRIDE; | 44 virtual bool Accept() OVERRIDE; |
45 virtual bool Cancel() OVERRIDE; | 45 virtual bool Cancel() OVERRIDE; |
46 virtual void InfoBarDismissed() OVERRIDE; | 46 virtual void InfoBarDismissed() OVERRIDE; |
47 | 47 |
48 private: | 48 private: |
| 49 AppNotifyChannelUIInfoBarDelegate(AppNotifyChannelUIImpl* creator, |
| 50 InfoBarService* infobar_service, |
| 51 const std::string& app_name); |
| 52 virtual ~AppNotifyChannelUIInfoBarDelegate(); |
| 53 |
49 AppNotifyChannelUIImpl* creator_; | 54 AppNotifyChannelUIImpl* creator_; |
50 std::string app_name_; | 55 std::string app_name_; |
51 | 56 |
52 DISALLOW_COPY_AND_ASSIGN(AppNotifyChannelUIInfoBarDelegate); | 57 DISALLOW_COPY_AND_ASSIGN(AppNotifyChannelUIInfoBarDelegate); |
53 }; | 58 }; |
54 | 59 |
55 AppNotifyChannelUIInfoBarDelegate::AppNotifyChannelUIInfoBarDelegate( | 60 // static |
56 AppNotifyChannelUIImpl* creator, | 61 void AppNotifyChannelUIInfoBarDelegate::Create(InfoBarService* infobar_service, |
57 InfoBarService* infobar_service, | 62 AppNotifyChannelUIImpl* creator, |
58 const std::string& app_name) | 63 const std::string& app_name) { |
59 : ConfirmInfoBarDelegate(infobar_service), | 64 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
60 creator_(creator), | 65 new AppNotifyChannelUIInfoBarDelegate(creator, infobar_service, |
61 app_name_(app_name) { | 66 app_name))); |
62 } | |
63 | |
64 AppNotifyChannelUIInfoBarDelegate::~AppNotifyChannelUIInfoBarDelegate() { | |
65 } | 67 } |
66 | 68 |
67 string16 AppNotifyChannelUIInfoBarDelegate::GetMessageText() const { | 69 string16 AppNotifyChannelUIInfoBarDelegate::GetMessageText() const { |
68 return l10n_util::GetStringFUTF16(IDS_APP_NOTIFICATION_NEED_SIGNIN, | 70 return l10n_util::GetStringFUTF16(IDS_APP_NOTIFICATION_NEED_SIGNIN, |
69 UTF8ToUTF16(app_name_)); | 71 UTF8ToUTF16(app_name_)); |
70 } | 72 } |
71 | 73 |
72 string16 AppNotifyChannelUIInfoBarDelegate::GetButtonLabel( | 74 string16 AppNotifyChannelUIInfoBarDelegate::GetButtonLabel( |
73 InfoBarButton button) const { | 75 InfoBarButton button) const { |
74 if (button == BUTTON_OK) { | 76 if (button == BUTTON_OK) { |
(...skipping 13 matching lines...) Expand all Loading... |
88 | 90 |
89 bool AppNotifyChannelUIInfoBarDelegate::Cancel() { | 91 bool AppNotifyChannelUIInfoBarDelegate::Cancel() { |
90 creator_->OnInfoBarResult(false); | 92 creator_->OnInfoBarResult(false); |
91 return true; | 93 return true; |
92 } | 94 } |
93 | 95 |
94 void AppNotifyChannelUIInfoBarDelegate::InfoBarDismissed() { | 96 void AppNotifyChannelUIInfoBarDelegate::InfoBarDismissed() { |
95 Cancel(); | 97 Cancel(); |
96 } | 98 } |
97 | 99 |
| 100 AppNotifyChannelUIInfoBarDelegate::AppNotifyChannelUIInfoBarDelegate( |
| 101 AppNotifyChannelUIImpl* creator, |
| 102 InfoBarService* infobar_service, |
| 103 const std::string& app_name) |
| 104 : ConfirmInfoBarDelegate(infobar_service), |
| 105 creator_(creator), |
| 106 app_name_(app_name) { |
| 107 } |
| 108 |
| 109 AppNotifyChannelUIInfoBarDelegate::~AppNotifyChannelUIInfoBarDelegate() { |
| 110 } |
| 111 |
98 } // namespace | 112 } // namespace |
99 | 113 |
100 | 114 |
101 AppNotifyChannelUIImpl::AppNotifyChannelUIImpl( | 115 AppNotifyChannelUIImpl::AppNotifyChannelUIImpl( |
102 Profile* profile, | 116 Profile* profile, |
103 content::WebContents* web_contents, | 117 content::WebContents* web_contents, |
104 const std::string& app_name, | 118 const std::string& app_name, |
105 AppNotifyChannelUI::UIType ui_type) | 119 AppNotifyChannelUI::UIType ui_type) |
106 : profile_(profile->GetOriginalProfile()), | 120 : profile_(profile->GetOriginalProfile()), |
107 web_contents_(web_contents), | 121 web_contents_(web_contents), |
(...skipping 27 matching lines...) Expand all Loading... |
135 profile_)) { | 149 profile_)) { |
136 delegate_->OnSyncSetupResult(false); | 150 delegate_->OnSyncSetupResult(false); |
137 return; | 151 return; |
138 } | 152 } |
139 | 153 |
140 if (ui_type_ == NO_INFOBAR) { | 154 if (ui_type_ == NO_INFOBAR) { |
141 OnInfoBarResult(true); | 155 OnInfoBarResult(true); |
142 return; | 156 return; |
143 } | 157 } |
144 | 158 |
145 InfoBarService* infobar_service = | 159 AppNotifyChannelUIInfoBarDelegate::Create( |
146 InfoBarService::FromWebContents(web_contents_); | 160 InfoBarService::FromWebContents(web_contents_), this, app_name_); |
147 infobar_service->AddInfoBar(new AppNotifyChannelUIInfoBarDelegate( | |
148 this, infobar_service, app_name_)); | |
149 } | 161 } |
150 | 162 |
151 void AppNotifyChannelUIImpl::OnInfoBarResult(bool accepted) { | 163 void AppNotifyChannelUIImpl::OnInfoBarResult(bool accepted) { |
152 if (!accepted) { | 164 if (!accepted) { |
153 delegate_->OnSyncSetupResult(false); | 165 delegate_->OnSyncSetupResult(false); |
154 return; | 166 return; |
155 } | 167 } |
156 | 168 |
157 StartObservingSync(); | 169 StartObservingSync(); |
158 // Bring up the login page. | 170 // Bring up the login page. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 220 } |
209 | 221 |
210 void AppNotifyChannelUIImpl::StopObservingSync() { | 222 void AppNotifyChannelUIImpl::StopObservingSync() { |
211 CHECK(observing_sync_); | 223 CHECK(observing_sync_); |
212 observing_sync_ = false; | 224 observing_sync_ = false; |
213 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 225 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
214 profile_)->RemoveObserver(this); | 226 profile_)->RemoveObserver(this); |
215 } | 227 } |
216 | 228 |
217 } // namespace extensions | 229 } // namespace extensions |
OLD | NEW |