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

Side by Side Diff: chrome/browser/services/gcm/gcm_client_mock.h

Issue 165993005: [GCM] Make sure GCM checkout logic is invoked when the profile is signed out (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address more feedback Created 6 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 | Annotate | Revision Log
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_SERVICES_GCM_GCM_CLIENT_MOCK_H_ 5 #ifndef CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_
6 #define CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_ 6 #define CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "google_apis/gcm/gcm_client.h" 9 #include "google_apis/gcm/gcm_client.h"
10 10
11 namespace gcm { 11 namespace gcm {
12 12
13 class GCMClientMock : public GCMClient { 13 class GCMClientMock : public GCMClient {
14 public: 14 public:
15 enum Status { 15 enum Status {
16 NOT_READY, 16 UNINITIALIZED,
17 READY 17 LOADED,
18 CHECKED_OUT
19 };
20
21 enum LoadingDelay {
22 NO_LOADING_DELAY,
23 LOADING_DELAY,
Nicolas Zea 2014/02/21 20:58:58 nit: loading_delay -> delay_load (make it an actio
jianli 2014/02/22 00:03:06 Done.
18 }; 24 };
19 25
20 enum ErrorSimulation { 26 enum ErrorSimulation {
21 ALWAYS_SUCCEED, 27 ALWAYS_SUCCEED,
22 FORCE_ERROR 28 FORCE_ERROR
23 }; 29 };
24 30
25 // |status| denotes if the fake client is ready or not at the beginning. 31 // |loading_delay| denotes if the check-in should be delayed.
26 // |error_simulation| denotes if we should simulate server error. 32 // |error_simulation| denotes if we should simulate server error.
27 GCMClientMock(Status status, ErrorSimulation error_simulation); 33 GCMClientMock(LoadingDelay loading_delay, ErrorSimulation error_simulation);
28 virtual ~GCMClientMock(); 34 virtual ~GCMClientMock();
29 35
30 // Overridden from GCMClient: 36 // Overridden from GCMClient:
31 // Called on IO thread. 37 // Called on IO thread.
32 virtual void Initialize( 38 virtual void Initialize(
33 const checkin_proto::ChromeBuildProto& chrome_build_proto, 39 const checkin_proto::ChromeBuildProto& chrome_build_proto,
34 const base::FilePath& store_path, 40 const base::FilePath& store_path,
35 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, 41 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
36 const scoped_refptr<net::URLRequestContextGetter>& 42 const scoped_refptr<net::URLRequestContextGetter>&
37 url_request_context_getter, 43 url_request_context_getter,
38 Delegate* delegate) OVERRIDE; 44 Delegate* delegate) OVERRIDE;
45 virtual void Load() OVERRIDE;
39 virtual void CheckOut() OVERRIDE; 46 virtual void CheckOut() OVERRIDE;
40 virtual void Register(const std::string& app_id, 47 virtual void Register(const std::string& app_id,
41 const std::string& cert, 48 const std::string& cert,
42 const std::vector<std::string>& sender_ids) OVERRIDE; 49 const std::vector<std::string>& sender_ids) OVERRIDE;
43 virtual void Unregister(const std::string& app_id) OVERRIDE; 50 virtual void Unregister(const std::string& app_id) OVERRIDE;
44 virtual void Send(const std::string& app_id, 51 virtual void Send(const std::string& app_id,
45 const std::string& receiver_id, 52 const std::string& receiver_id,
46 const OutgoingMessage& message) OVERRIDE; 53 const OutgoingMessage& message) OVERRIDE;
47 virtual bool IsReady() const OVERRIDE; 54
55 // Initiate the loading that has been delayed.
56 // Called on UI thread.
57 void PerformDelayedLoading();
48 58
49 // Simulate receiving something from the server. 59 // Simulate receiving something from the server.
50 // Called on UI thread. 60 // Called on UI thread.
51 void ReceiveMessage(const std::string& app_id, 61 void ReceiveMessage(const std::string& app_id,
52 const IncomingMessage& message); 62 const IncomingMessage& message);
53 void DeleteMessages(const std::string& app_id); 63 void DeleteMessages(const std::string& app_id);
54 64
55 // Can only transition from non-ready to ready.
56 void SetReady();
57
58 static std::string GetRegistrationIdFromSenderIds( 65 static std::string GetRegistrationIdFromSenderIds(
59 const std::vector<std::string>& sender_ids); 66 const std::vector<std::string>& sender_ids);
60 67
68 Status status() const { return status_; }
69
61 private: 70 private:
62 // Called on IO thread. 71 // Called on IO thread.
72 void CheckinFinished();
63 void RegisterFinished(const std::string& app_id, 73 void RegisterFinished(const std::string& app_id,
64 const std::string& registrion_id); 74 const std::string& registrion_id);
65 void SendFinished(const std::string& app_id, const std::string& message_id); 75 void SendFinished(const std::string& app_id, const std::string& message_id);
66 void MessageReceived(const std::string& app_id, 76 void MessageReceived(const std::string& app_id,
67 const IncomingMessage& message); 77 const IncomingMessage& message);
68 void MessagesDeleted(const std::string& app_id); 78 void MessagesDeleted(const std::string& app_id);
69 void MessageSendError(const std::string& app_id, 79 void MessageSendError(const std::string& app_id,
70 const std::string& message_id); 80 const std::string& message_id);
71 void SetReadyOnIO();
72 81
73 Delegate* delegate_; 82 Delegate* delegate_;
74 Status status_; 83 Status status_;
84 LoadingDelay loading_delay_;
75 ErrorSimulation error_simulation_; 85 ErrorSimulation error_simulation_;
76 86
77 DISALLOW_COPY_AND_ASSIGN(GCMClientMock); 87 DISALLOW_COPY_AND_ASSIGN(GCMClientMock);
78 }; 88 };
79 89
80 } // namespace gcm 90 } // namespace gcm
81 91
82 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_ 92 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_CLIENT_MOCK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698