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
3 // found in the LICENSE file.
5 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/browser_context.h"
16 BrowserContextKeyedService
* FakeGCMProfileService::Build(
17 content::BrowserContext
* context
) {
18 Profile
* profile
= static_cast<Profile
*>(context
);
20 return new FakeGCMProfileService(profile
);
24 void FakeGCMProfileService::EnableGCMForTesting() {
25 GCMProfileService::enable_gcm_for_testing_
= true;
28 FakeGCMProfileService::FakeGCMProfileService(Profile
* profile
)
29 : GCMProfileService(profile
),
32 FakeGCMProfileService::~FakeGCMProfileService() {}
34 void FakeGCMProfileService::Register(const std::string
& app_id
,
35 const std::vector
<std::string
>& sender_ids
,
36 const std::string
& cert
,
37 RegisterCallback callback
) {
38 base::MessageLoop::current()->PostTask(
40 base::Bind(&FakeGCMProfileService::RegisterFinished
,
41 base::Unretained(this),
48 void FakeGCMProfileService::RegisterFinished(
49 const std::string
& app_id
,
50 const std::vector
<std::string
>& sender_ids
,
51 const std::string
& cert
,
52 RegisterCallback callback
) {
54 last_registered_app_id_
= app_id
;
55 last_registered_sender_ids_
= sender_ids
;
56 last_registered_cert_
= cert
;
59 callback
.Run(base::UintToString(sender_ids
.size()), GCMClient::SUCCESS
);
62 void FakeGCMProfileService::Send(const std::string
& app_id
,
63 const std::string
& receiver_id
,
64 const GCMClient::OutgoingMessage
& message
,
65 SendCallback callback
) {
66 base::MessageLoop::current()->PostTask(
68 base::Bind(&FakeGCMProfileService::SendFinished
,
69 base::Unretained(this),
76 void FakeGCMProfileService::SendFinished(
77 const std::string
& app_id
,
78 const std::string
& receiver_id
,
79 const GCMClient::OutgoingMessage
& message
,
80 SendCallback callback
) {
82 last_sent_message_
= message
;
83 last_receiver_id_
= receiver_id
;
86 callback
.Run(message
.id
, GCMClient::SUCCESS
);