| OLD | NEW |
| 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 "content/common/net/url_fetcher.h" | 11 #include "content/public/common/url_fetcher_delegate.h" |
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 | 13 |
| 14 class Profile; | 14 class Profile; |
| 15 | 15 |
| 16 // This class uses the browser login credentials to fetch a channel ID for an | 16 // This class uses the browser login credentials to fetch a channel ID for an |
| 17 // app to use when sending server push notifications. | 17 // app to use when sending server push notifications. |
| 18 class AppNotifyChannelSetup | 18 class AppNotifyChannelSetup |
| 19 : public URLFetcher::Delegate, | 19 : public content::URLFetcherDelegate, |
| 20 public base::RefCountedThreadSafe<AppNotifyChannelSetup> { | 20 public base::RefCountedThreadSafe<AppNotifyChannelSetup> { |
| 21 public: | 21 public: |
| 22 class Delegate { | 22 class Delegate { |
| 23 public: | 23 public: |
| 24 // If successful, |channel_id| will be non-empty. On failure, |channel_id| | 24 // 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 | 25 // will be empty and |error| will contain an error to report to the JS |
| 26 // callback. | 26 // callback. |
| 27 virtual void AppNotifyChannelSetupComplete(const std::string& channel_id, | 27 virtual void AppNotifyChannelSetupComplete(const std::string& channel_id, |
| 28 const std::string& error, | 28 const std::string& error, |
| 29 int return_route_id, | 29 int return_route_id, |
| 30 int callback_id) = 0; | 30 int callback_id) = 0; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 AppNotifyChannelSetup(Profile* profile, | 33 AppNotifyChannelSetup(Profile* profile, |
| 34 const std::string& client_id, | 34 const std::string& client_id, |
| 35 const GURL& requestor_url, | 35 const GURL& requestor_url, |
| 36 int return_route_id, | 36 int return_route_id, |
| 37 int callback_id, | 37 int callback_id, |
| 38 base::WeakPtr<Delegate> delegate); | 38 base::WeakPtr<Delegate> delegate); |
| 39 | 39 |
| 40 // This begins the process of fetching the channel id using the browser login | 40 // 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 | 41 // credentials. If the user isn't logged in to chrome, this will first cause a |
| 42 // prompt to appear asking the user to log in. | 42 // prompt to appear asking the user to log in. |
| 43 void Start(); | 43 void Start(); |
| 44 | 44 |
| 45 protected: | 45 protected: |
| 46 // URLFetcher::Delegate. | 46 // content::URLFetcherDelegate. |
| 47 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 47 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 friend class base::RefCountedThreadSafe<AppNotifyChannelSetup>; | 50 friend class base::RefCountedThreadSafe<AppNotifyChannelSetup>; |
| 51 | 51 |
| 52 virtual ~AppNotifyChannelSetup(); | 52 virtual ~AppNotifyChannelSetup(); |
| 53 | 53 |
| 54 void ReportResult(const std::string& channel_id, const std::string& error); | 54 void ReportResult(const std::string& channel_id, const std::string& error); |
| 55 | 55 |
| 56 Profile* profile_; | 56 Profile* profile_; |
| 57 std::string client_id_; | 57 std::string client_id_; |
| 58 GURL requestor_url_; | 58 GURL requestor_url_; |
| 59 int return_route_id_; | 59 int return_route_id_; |
| 60 int callback_id_; | 60 int callback_id_; |
| 61 base::WeakPtr<Delegate> delegate_; | 61 base::WeakPtr<Delegate> delegate_; |
| 62 scoped_ptr<URLFetcher> url_fetcher_; | 62 scoped_ptr<URLFetcher> url_fetcher_; |
| 63 | 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(AppNotifyChannelSetup); | 64 DISALLOW_COPY_AND_ASSIGN(AppNotifyChannelSetup); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 #endif // CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_SETUP_H_ | 67 #endif // CHROME_BROWSER_EXTENSIONS_APP_NOTIFY_CHANNEL_SETUP_H_ |
| OLD | NEW |