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

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: 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
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/gcm_driver.h"
Peter Beverloo 2017/02/07 18:11:08 nit: IWYU means we should include the following in
johnme 2017/02/08 14:14:36 Done.
14 #include "components/gcm_driver/gcm_profile_service.h" 14 #include "components/gcm_driver/gcm_profile_service.h"
15 15
16 class Profile; 16 class Profile;
17 17
18 namespace content { 18 namespace content {
19 class BrowserContext; 19 class BrowserContext;
20 } // namespace content 20 } // namespace content
21 21
22 namespace gcm { 22 namespace gcm {
23 23
24 // Acts as a bridge between GCM API and GCMClient layer for testing purposes. 24 // Acts as a bridge between GCM API and GCMClient layer for testing purposes.
25 class FakeGCMProfileService : public GCMProfileService { 25 class FakeGCMProfileService : public GCMProfileService {
26 public: 26 public:
27 typedef base::Callback<void(const std::string&)> UnregisterCallback;
28
29 // Helper function to be used with 27 // Helper function to be used with
30 // KeyedService::SetTestingFactory(). 28 // KeyedService::SetTestingFactory().
31 static std::unique_ptr<KeyedService> Build(content::BrowserContext* context); 29 static std::unique_ptr<KeyedService> Build(content::BrowserContext* context);
32 30
33 explicit FakeGCMProfileService(Profile* profile); 31 explicit FakeGCMProfileService(Profile* profile);
34 ~FakeGCMProfileService() override; 32 ~FakeGCMProfileService() override;
35 33
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); 34 void AddExpectedUnregisterResponse(GCMClient::Result result);
44 35
45 void SetUnregisterCallback(const UnregisterCallback& callback);
46
47 void DispatchMessage(const std::string& app_id, 36 void DispatchMessage(const std::string& app_id,
48 const IncomingMessage& message); 37 const IncomingMessage& message);
49 38
50 const OutgoingMessage& last_sent_message() const { 39 const OutgoingMessage& last_sent_message() const {
51 return last_sent_message_; 40 return last_sent_message_;
52 } 41 }
53 42
54 const std::string& last_receiver_id() const { 43 const std::string& last_receiver_id() const {
55 return last_receiver_id_; 44 return last_receiver_id_;
56 } 45 }
57 46
58 const std::string& last_registered_app_id() const { 47 const std::string& last_registered_app_id() const {
59 return last_registered_app_id_; 48 return last_registered_app_id_;
60 } 49 }
61 50
62 const std::vector<std::string>& last_registered_sender_ids() const { 51 const std::vector<std::string>& last_registered_sender_ids() const {
63 return last_registered_sender_ids_; 52 return last_registered_sender_ids_;
64 } 53 }
65 54
66 void set_collect(bool collect) { 55 void set_collect(bool collect) {
67 collect_ = collect; 56 collect_ = collect;
68 } 57 }
69 58
59 // Simple offline simulation: requests fail after max backoff.
60 void set_offline(bool is_offline) { is_offline_ = is_offline; }
61
70 private: 62 private:
63 class CustomFakeGCMDriver;
64 friend class CustomFakeGCMDriver;
Peter Beverloo 2017/02/07 18:11:08 nit: since the CustomFakeGCMDriver already stores
johnme 2017/02/08 14:14:36 No, it's not just is_offline_, it's also collect_,
65
71 // Indicates whether the service will collect paramters of the calls for 66 // Indicates whether the service will collect paramters of the calls for
72 // furter verification in tests. 67 // further verification in tests.
73 bool collect_; 68 bool collect_ = false;
74 // Used to give each registration a unique registration id. Does not decrease 69
75 // when unregister is called. 70 bool is_offline_ = false;
Peter Beverloo 2017/02/07 18:11:08 nit: it's a bit unfortunate that collect_ is docum
johnme 2017/02/08 14:14:36 Done (documented both at public setter).
76 int registration_count_; 71
77 std::string last_registered_app_id_; 72 std::string last_registered_app_id_;
78 std::vector<std::string> last_registered_sender_ids_; 73 std::vector<std::string> last_registered_sender_ids_;
79 std::list<GCMClient::Result> unregister_responses_; 74 std::list<GCMClient::Result> unregister_responses_;
80 OutgoingMessage last_sent_message_; 75 OutgoingMessage last_sent_message_;
81 std::string last_receiver_id_; 76 std::string last_receiver_id_;
82 UnregisterCallback unregister_callback_;
83 77
84 DISALLOW_COPY_AND_ASSIGN(FakeGCMProfileService); 78 DISALLOW_COPY_AND_ASSIGN(FakeGCMProfileService);
85 }; 79 };
86 80
87 } // namespace gcm 81 } // namespace gcm
88 82
89 #endif // CHROME_BROWSER_GCM_FAKE_GCM_PROFILE_SERVICE_H_ 83 #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') | chrome/browser/gcm/fake_gcm_profile_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698