OLD | NEW |
(Empty) | |
| 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_EXTENSIONS_APP_NOTIFY_CHANNEL_UI_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_UI_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" |
| 12 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 13 |
| 14 class Browser; |
| 15 class TabContentsWrapper; |
| 16 |
| 17 // An interface for prompting a user to sign in to sync so that we can create |
| 18 // an app notification channel for one of their apps. |
| 19 class AppNotifyChannelUI { |
| 20 public: |
| 21 virtual ~AppNotifyChannelUI() {} |
| 22 |
| 23 class Delegate { |
| 24 public: |
| 25 // A callback for whether the user successfully set up sync or not. |
| 26 virtual void OnSyncSetupResult(bool enabled) = 0; |
| 27 }; |
| 28 |
| 29 // Shows a prompt for sync setup - |delegate| will be called back later when |
| 30 // setup is complete or cancelled. This should only be called once per |
| 31 // instance. |
| 32 virtual void PromptSyncSetup(Delegate* delegate) = 0; |
| 33 }; |
| 34 |
| 35 |
| 36 class AppNotifyChannelUIImpl : public AppNotifyChannelUI, |
| 37 public ProfileSyncServiceObserver { |
| 38 public: |
| 39 AppNotifyChannelUIImpl(Browser* browser, |
| 40 TabContentsWrapper* wrapper, |
| 41 const std::string& app_name); |
| 42 virtual ~AppNotifyChannelUIImpl(); |
| 43 |
| 44 // AppNotifyChannelUI. |
| 45 virtual void PromptSyncSetup(AppNotifyChannelUI::Delegate* delegate) OVERRIDE; |
| 46 |
| 47 protected: |
| 48 // A private class we use to put up an infobar - its lifetime is managed by |
| 49 // |wrapper_|, so we don't have one as an instance variable. |
| 50 class InfoBar; |
| 51 friend class AppNotifyChannelUIImpl::InfoBar; |
| 52 |
| 53 // Called by our InfoBar when it's accepted or cancelled/closed. |
| 54 void OnInfoBarResult(bool accepted); |
| 55 |
| 56 // ProfileSyncServiceObserver. |
| 57 virtual void OnStateChanged() OVERRIDE; |
| 58 |
| 59 private: |
| 60 void StartObservingSync(); |
| 61 void StopObservingSync(); |
| 62 |
| 63 Browser* browser_; |
| 64 TabContentsWrapper* wrapper_; |
| 65 std::string app_name_; |
| 66 AppNotifyChannelUI::Delegate* delegate_; |
| 67 |
| 68 // Have we registered ourself as a ProfileSyncServiceObserver? |
| 69 bool observing_sync_; |
| 70 |
| 71 // This is for working around a bug where the first ProfileSyncServiceObserver |
| 72 // callback after starting the sync login process erroneously reports |
| 73 // SetupInProgress as false. See crbug.com/101842. |
| 74 bool got_first_sync_callback_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(AppNotifyChannelUIImpl); |
| 77 }; |
| 78 |
| 79 #endif // CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_UI_H_ |
OLD | NEW |