Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/extensions/app_notify_channel_setup.h

Issue 8400027: Add code to prompt for browser login during app notification setup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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_SETUP_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_SETUP_H_
6 #define CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_SETUP_H_ 6 #define CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_SETUP_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/extensions/app_notify_channel_ui.h"
11 #include "content/public/common/url_fetcher_delegate.h" 12 #include "content/public/common/url_fetcher_delegate.h"
12 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
13 14
14 class Profile; 15 class Profile;
15 16
16 // This class uses the browser login credentials to fetch a channel ID for an 17 // This class uses the browser login credentials to fetch a channel ID for an
17 // app to use when sending server push notifications. 18 // app to use when sending server push notifications.
18 class AppNotifyChannelSetup 19 class AppNotifyChannelSetup
19 : public content::URLFetcherDelegate, 20 : public content::URLFetcherDelegate,
21 public AppNotifyChannelUI::Delegate,
20 public base::RefCountedThreadSafe<AppNotifyChannelSetup> { 22 public base::RefCountedThreadSafe<AppNotifyChannelSetup> {
21 public: 23 public:
22 class Delegate { 24 class Delegate {
23 public: 25 public:
24 // If successful, |channel_id| will be non-empty. On failure, |channel_id| 26 // If successful, |channel_id| will be non-empty. On failure, |channel_id|
25 // will be empty and |error| will contain an error to report to the JS 27 // will be empty and |error| will contain an error to report to the JS
26 // callback. 28 // callback.
27 virtual void AppNotifyChannelSetupComplete(const std::string& channel_id, 29 virtual void AppNotifyChannelSetupComplete(const std::string& channel_id,
28 const std::string& error, 30 const std::string& error,
29 int return_route_id, 31 int return_route_id,
30 int callback_id) = 0; 32 int callback_id) = 0;
31 }; 33 };
32 34
35 // Ownership of |ui| is transferred to this object.
33 AppNotifyChannelSetup(Profile* profile, 36 AppNotifyChannelSetup(Profile* profile,
34 const std::string& client_id, 37 const std::string& client_id,
35 const GURL& requestor_url, 38 const GURL& requestor_url,
36 int return_route_id, 39 int return_route_id,
37 int callback_id, 40 int callback_id,
41 AppNotifyChannelUI* ui,
38 base::WeakPtr<Delegate> delegate); 42 base::WeakPtr<Delegate> delegate);
39 43
40 // This begins the process of fetching the channel id using the browser login 44 // This begins the process of fetching the channel id using the browser login
41 // credentials. If the user isn't logged in to chrome, this will first cause a 45 // credentials (or using |ui_| to prompt for login if needed).
42 // prompt to appear asking the user to log in.
43 void Start(); 46 void Start();
44 47
45 protected: 48 protected:
46 // content::URLFetcherDelegate. 49 // content::URLFetcherDelegate.
47 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; 50 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
48 51
52 // AppNotifyChannelUI::Delegate.
53 virtual void OnSyncSetupResult(bool enabled) OVERRIDE;
54
49 private: 55 private:
50 friend class base::RefCountedThreadSafe<AppNotifyChannelSetup>; 56 friend class base::RefCountedThreadSafe<AppNotifyChannelSetup>;
57 virtual ~AppNotifyChannelSetup();
51 58
52 virtual ~AppNotifyChannelSetup(); 59 void BeginFetch();
53 60
54 void ReportResult(const std::string& channel_id, const std::string& error); 61 void ReportResult(const std::string& channel_id, const std::string& error);
55 62
56 Profile* profile_; 63 Profile* profile_;
57 std::string client_id_; 64 std::string client_id_;
58 GURL requestor_url_; 65 GURL requestor_url_;
59 int return_route_id_; 66 int return_route_id_;
60 int callback_id_; 67 int callback_id_;
61 base::WeakPtr<Delegate> delegate_; 68 base::WeakPtr<Delegate> delegate_;
62 scoped_ptr<content::URLFetcher> url_fetcher_; 69 scoped_ptr<content::URLFetcher> url_fetcher_;
70 scoped_ptr<AppNotifyChannelUI> ui_;
63 71
64 DISALLOW_COPY_AND_ASSIGN(AppNotifyChannelSetup); 72 DISALLOW_COPY_AND_ASSIGN(AppNotifyChannelSetup);
65 }; 73 };
66 74
67 #endif // CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_SETUP_H_ 75 #endif // CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_SETUP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698