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

Side by Side Diff: chrome/browser/gcm/fake_gcm_profile_service.h

Issue 2675293003: Push API: Don't wait for network when unsubscribing (Closed)
Patch Set: Address peter's review comments Created 3 years, 10 months 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
« no previous file with comments | « no previous file | chrome/browser/gcm/fake_gcm_profile_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_GCM_FAKE_GCM_PROFILE_SERVICE_H_ 5 #ifndef CHROME_BROWSER_GCM_FAKE_GCM_PROFILE_SERVICE_H_
6 #define CHROME_BROWSER_GCM_FAKE_GCM_PROFILE_SERVICE_H_ 6 #define CHROME_BROWSER_GCM_FAKE_GCM_PROFILE_SERVICE_H_
7 7
8 #include <list> 8 #include <list>
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "components/gcm_driver/gcm_driver.h" 13 #include "components/gcm_driver/common/gcm_messages.h"
14 #include "components/gcm_driver/gcm_client.h"
14 #include "components/gcm_driver/gcm_profile_service.h" 15 #include "components/gcm_driver/gcm_profile_service.h"
15 16
16 class Profile; 17 class Profile;
17 18
18 namespace content { 19 namespace content {
19 class BrowserContext; 20 class BrowserContext;
20 } // namespace content 21 } // namespace content
21 22
22 namespace gcm { 23 namespace gcm {
23 24
24 // Acts as a bridge between GCM API and GCMClient layer for testing purposes. 25 // Acts as a bridge between GCM API and GCMClient layer for testing purposes.
25 class FakeGCMProfileService : public GCMProfileService { 26 class FakeGCMProfileService : public GCMProfileService {
26 public: 27 public:
27 typedef base::Callback<void(const std::string&)> UnregisterCallback;
28
29 // Helper function to be used with 28 // Helper function to be used with
30 // KeyedService::SetTestingFactory(). 29 // KeyedService::SetTestingFactory().
31 static std::unique_ptr<KeyedService> Build(content::BrowserContext* context); 30 static std::unique_ptr<KeyedService> Build(content::BrowserContext* context);
32 31
33 explicit FakeGCMProfileService(Profile* profile); 32 explicit FakeGCMProfileService(Profile* profile);
34 ~FakeGCMProfileService() override; 33 ~FakeGCMProfileService() override;
35 34
36 void RegisterFinished(const std::string& app_id,
37 const std::vector<std::string>& sender_ids);
38 void UnregisterFinished(const std::string& app_id);
39 void SendFinished(const std::string& app_id,
40 const std::string& receiver_id,
41 const OutgoingMessage& message);
42
43 void AddExpectedUnregisterResponse(GCMClient::Result result); 35 void AddExpectedUnregisterResponse(GCMClient::Result result);
44 36
45 void SetUnregisterCallback(const UnregisterCallback& callback);
46
47 void DispatchMessage(const std::string& app_id, 37 void DispatchMessage(const std::string& app_id,
48 const IncomingMessage& message); 38 const IncomingMessage& message);
49 39
50 const OutgoingMessage& last_sent_message() const { 40 const OutgoingMessage& last_sent_message() const {
51 return last_sent_message_; 41 return last_sent_message_;
52 } 42 }
53 43
54 const std::string& last_receiver_id() const { 44 const std::string& last_receiver_id() const {
55 return last_receiver_id_; 45 return last_receiver_id_;
56 } 46 }
57 47
58 const std::string& last_registered_app_id() const { 48 const std::string& last_registered_app_id() const {
59 return last_registered_app_id_; 49 return last_registered_app_id_;
60 } 50 }
61 51
62 const std::vector<std::string>& last_registered_sender_ids() const { 52 const std::vector<std::string>& last_registered_sender_ids() const {
63 return last_registered_sender_ids_; 53 return last_registered_sender_ids_;
64 } 54 }
65 55
66 void set_collect(bool collect) { 56 // Set whether the service will collect parameters of the calls for further
67 collect_ = collect; 57 // verification in tests.
68 } 58 void set_collect(bool collect) { collect_ = collect; }
59
60 // Crude offline simulation: requests fail and never run their callbacks (in
61 // reality, callbacks run within GetGCMBackoffPolicy().maximum_backoff_ms).
62 void set_offline(bool is_offline) { is_offline_ = is_offline; }
69 63
70 private: 64 private:
71 // Indicates whether the service will collect paramters of the calls for 65 class CustomFakeGCMDriver;
72 // furter verification in tests. 66 friend class CustomFakeGCMDriver;
73 bool collect_; 67
74 // Used to give each registration a unique registration id. Does not decrease 68 bool collect_ = false;
75 // when unregister is called. 69 bool is_offline_ = false;
76 int registration_count_; 70
77 std::string last_registered_app_id_; 71 std::string last_registered_app_id_;
78 std::vector<std::string> last_registered_sender_ids_; 72 std::vector<std::string> last_registered_sender_ids_;
79 std::list<GCMClient::Result> unregister_responses_; 73 std::list<GCMClient::Result> unregister_responses_;
80 OutgoingMessage last_sent_message_; 74 OutgoingMessage last_sent_message_;
81 std::string last_receiver_id_; 75 std::string last_receiver_id_;
82 UnregisterCallback unregister_callback_;
83 76
84 DISALLOW_COPY_AND_ASSIGN(FakeGCMProfileService); 77 DISALLOW_COPY_AND_ASSIGN(FakeGCMProfileService);
85 }; 78 };
86 79
87 } // namespace gcm 80 } // namespace gcm
88 81
89 #endif // CHROME_BROWSER_GCM_FAKE_GCM_PROFILE_SERVICE_H_ 82 #endif // CHROME_BROWSER_GCM_FAKE_GCM_PROFILE_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/gcm/fake_gcm_profile_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698