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

Side by Side Diff: chromeos/dbus/sms_client.cc

Issue 91373004: Move DBusClient stub implementations into separate files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years 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
« no previous file with comments | « chromeos/dbus/sms_client.h ('k') | chromeos/network/network_sms_handler_unittest.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chromeos/dbus/sms_client.h" 4 #include "chromeos/dbus/sms_client.h"
5 5
6 #include <map> 6 #include <map>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/location.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/stl_util.h" 15 #include "base/stl_util.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "chromeos/chromeos_switches.h" 18 #include "chromeos/chromeos_switches.h"
18 #include "dbus/bus.h" 19 #include "dbus/bus.h"
19 #include "dbus/message.h" 20 #include "dbus/message.h"
20 #include "dbus/object_proxy.h" 21 #include "dbus/object_proxy.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 79
79 dbus::Bus* bus_; 80 dbus::Bus* bus_;
80 81
81 // Note: This should remain the last member so it'll be destroyed and 82 // Note: This should remain the last member so it'll be destroyed and
82 // invalidate its weak pointers before any other members are destroyed. 83 // invalidate its weak pointers before any other members are destroyed.
83 base::WeakPtrFactory<SMSClientImpl> weak_ptr_factory_; 84 base::WeakPtrFactory<SMSClientImpl> weak_ptr_factory_;
84 85
85 DISALLOW_COPY_AND_ASSIGN(SMSClientImpl); 86 DISALLOW_COPY_AND_ASSIGN(SMSClientImpl);
86 }; 87 };
87 88
88 class SMSClientStubImpl : public SMSClient {
89 public:
90 SMSClientStubImpl() : weak_ptr_factory_(this) {}
91 virtual ~SMSClientStubImpl() {}
92
93 virtual void Init(dbus::Bus* bus) OVERRIDE {}
94
95 virtual void GetAll(const std::string& service_name,
96 const dbus::ObjectPath& object_path,
97 const GetAllCallback& callback) OVERRIDE {
98 if (!CommandLine::ForCurrentProcess()->HasSwitch(
99 chromeos::switches::kSmsTestMessages))
100 return;
101
102 // Ownership passed to callback
103 base::DictionaryValue *sms = new base::DictionaryValue();
104 sms->SetString("Number", "000-000-0000");
105 sms->SetString("Text",
106 "SMSClientStubImpl: Test Message: " + object_path.value());
107 sms->SetString("Timestamp", "Fri Jun 8 13:26:04 EDT 2012");
108
109 // Run callback asynchronously.
110 if (callback.is_null())
111 return;
112 base::MessageLoop::current()->PostTask(
113 FROM_HERE,
114 base::Bind(&SMSClientStubImpl::OnGetAll,
115 weak_ptr_factory_.GetWeakPtr(),
116 base::Owned(sms),
117 callback));
118 }
119
120 private:
121 void OnGetAll(base::DictionaryValue *sms,
122 const GetAllCallback& callback) {
123 callback.Run(*sms);
124 }
125
126 base::WeakPtrFactory<SMSClientStubImpl> weak_ptr_factory_;
127
128 DISALLOW_COPY_AND_ASSIGN(SMSClientStubImpl);
129 };
130
131 } // namespace 89 } // namespace
132 90
133 //////////////////////////////////////////////////////////////////////////////// 91 ////////////////////////////////////////////////////////////////////////////////
134 // SMSClient 92 // SMSClient
135 93
136 SMSClient::SMSClient() {} 94 SMSClient::SMSClient() {}
137 95
138 SMSClient::~SMSClient() {} 96 SMSClient::~SMSClient() {}
139 97
140 98
141 // static 99 // static
142 SMSClient* SMSClient::Create(DBusClientImplementationType type) { 100 SMSClient* SMSClient::Create() {
143 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) { 101 return new SMSClientImpl();
144 return new SMSClientImpl();
145 }
146 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
147 return new SMSClientStubImpl();
148 } 102 }
149 103
150 } // namespace chromeos 104 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/sms_client.h ('k') | chromeos/network/network_sms_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698