| 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 #ifndef CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_UI_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_UI_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_UI_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_UI_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 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 Profile; | 10 class Profile; |
| 15 class TabContents; | 11 class TabContents; |
| 16 | 12 |
| 17 // An interface for prompting a user to sign in to sync so that we can create | 13 // 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. | 14 // an app notification channel for one of their apps. |
| 19 class AppNotifyChannelUI { | 15 class AppNotifyChannelUI { |
| 20 public: | 16 public: |
| 21 virtual ~AppNotifyChannelUI() {} | 17 virtual ~AppNotifyChannelUI() {} |
| 22 | 18 |
| 23 // Used to customize the UI we show. | 19 // Used to customize the UI we show. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 virtual void OnSyncSetupResult(bool enabled) = 0; | 31 virtual void OnSyncSetupResult(bool enabled) = 0; |
| 36 | 32 |
| 37 protected: | 33 protected: |
| 38 virtual ~Delegate() {} | 34 virtual ~Delegate() {} |
| 39 }; | 35 }; |
| 40 | 36 |
| 41 // Shows a prompt for sync setup - |delegate| will be called back later when | 37 // Shows a prompt for sync setup - |delegate| will be called back later when |
| 42 // setup is complete or cancelled. This should only be called once per | 38 // setup is complete or cancelled. This should only be called once per |
| 43 // instance. | 39 // instance. |
| 44 virtual void PromptSyncSetup(Delegate* delegate) = 0; | 40 virtual void PromptSyncSetup(Delegate* delegate) = 0; |
| 45 }; | |
| 46 | 41 |
| 47 | 42 // Builds the platform specific AppNotifyChannelUI. |
| 48 class AppNotifyChannelUIImpl : public AppNotifyChannelUI, | 43 static AppNotifyChannelUI* Create(Profile* profile, |
| 49 public ProfileSyncServiceObserver { | 44 TabContents* tab_contents, |
| 50 public: | 45 const std::string& app_name, |
| 51 AppNotifyChannelUIImpl(Profile* profile, | 46 AppNotifyChannelUI::UIType ui_type); |
| 52 TabContents* tab_contents, | |
| 53 const std::string& app_name, | |
| 54 AppNotifyChannelUI::UIType ui_type); | |
| 55 virtual ~AppNotifyChannelUIImpl(); | |
| 56 | |
| 57 // AppNotifyChannelUI. | |
| 58 virtual void PromptSyncSetup(AppNotifyChannelUI::Delegate* delegate) OVERRIDE; | |
| 59 | |
| 60 protected: | |
| 61 // A private class we use to put up an infobar - its lifetime is managed by | |
| 62 // |tab_contents_|, so we don't have one as an instance variable. | |
| 63 class InfoBar; | |
| 64 friend class AppNotifyChannelUIImpl::InfoBar; | |
| 65 | |
| 66 // Called by our InfoBar when it's accepted or cancelled/closed. | |
| 67 void OnInfoBarResult(bool accepted); | |
| 68 | |
| 69 // ProfileSyncServiceObserver. | |
| 70 virtual void OnStateChanged() OVERRIDE; | |
| 71 | |
| 72 private: | |
| 73 void StartObservingSync(); | |
| 74 void StopObservingSync(); | |
| 75 | |
| 76 Profile* profile_; | |
| 77 TabContents* tab_contents_; | |
| 78 std::string app_name_; | |
| 79 AppNotifyChannelUI::UIType ui_type_; | |
| 80 AppNotifyChannelUI::Delegate* delegate_; | |
| 81 | |
| 82 // Have we registered ourself as a ProfileSyncServiceObserver? | |
| 83 bool observing_sync_; | |
| 84 | |
| 85 // This is for working around a bug that ProfileSyncService calls | |
| 86 // ProfileSyncServiceObserver::OnStateChanged callback many times | |
| 87 // after ShowLoginDialog is called and before the wizard is | |
| 88 // actually visible to the user. So we record if the wizard was | |
| 89 // shown to user and then wait for wizard to get dismissed. | |
| 90 // See crbug.com/101842. | |
| 91 bool wizard_shown_to_user_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(AppNotifyChannelUIImpl); | |
| 94 }; | 47 }; |
| 95 | 48 |
| 96 #endif // CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_UI_H_ | 49 #endif // CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_UI_H_ |
| OLD | NEW |