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

Side by Side Diff: chrome/browser/extensions/api/serial/serial_event_dispatcher.cc

Issue 216513002: Replace DCHECK(BrowserThread::CurrentlyOn) with DCHECK_CURRENTLY_ON in extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 #include "chrome/browser/extensions/api/serial/serial_event_dispatcher.h" 5 #include "chrome/browser/extensions/api/serial/serial_event_dispatcher.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/extensions/api/serial/serial_connection.h" 8 #include "chrome/browser/extensions/api/serial/serial_connection.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_manager.h" 10 #include "chrome/browser/profiles/profile_manager.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 SerialEventDispatcher::~SerialEventDispatcher() {} 52 SerialEventDispatcher::~SerialEventDispatcher() {}
53 53
54 SerialEventDispatcher::ReceiveParams::ReceiveParams() {} 54 SerialEventDispatcher::ReceiveParams::ReceiveParams() {}
55 55
56 SerialEventDispatcher::ReceiveParams::~ReceiveParams() {} 56 SerialEventDispatcher::ReceiveParams::~ReceiveParams() {}
57 57
58 void SerialEventDispatcher::PollConnection(const std::string& extension_id, 58 void SerialEventDispatcher::PollConnection(const std::string& extension_id,
59 int connection_id) { 59 int connection_id) {
60 DCHECK(BrowserThread::CurrentlyOn(thread_id_)); 60 DCHECK_CURRENTLY_ON(thread_id_);
61 61
62 ReceiveParams params; 62 ReceiveParams params;
63 params.thread_id = thread_id_; 63 params.thread_id = thread_id_;
64 params.profile_id = profile_; 64 params.profile_id = profile_;
65 params.extension_id = extension_id; 65 params.extension_id = extension_id;
66 params.connections = connections_; 66 params.connections = connections_;
67 params.connection_id = connection_id; 67 params.connection_id = connection_id;
68 68
69 StartReceive(params); 69 StartReceive(params);
70 } 70 }
71 71
72 // static 72 // static
73 void SerialEventDispatcher::StartReceive(const ReceiveParams& params) { 73 void SerialEventDispatcher::StartReceive(const ReceiveParams& params) {
74 DCHECK(BrowserThread::CurrentlyOn(params.thread_id)); 74 DCHECK_CURRENTLY_ON(params.thread_id);
75 75
76 SerialConnection* connection = 76 SerialConnection* connection =
77 params.connections->Get(params.extension_id, params.connection_id); 77 params.connections->Get(params.extension_id, params.connection_id);
78 if (!connection) 78 if (!connection)
79 return; 79 return;
80 DCHECK(params.extension_id == connection->owner_extension_id()); 80 DCHECK(params.extension_id == connection->owner_extension_id());
81 81
82 if (connection->paused()) 82 if (connection->paused())
83 return; 83 return;
84 84
85 connection->Receive(base::Bind(&ReceiveCallback, params)); 85 connection->Receive(base::Bind(&ReceiveCallback, params));
86 } 86 }
87 87
88 // static 88 // static
89 void SerialEventDispatcher::ReceiveCallback(const ReceiveParams& params, 89 void SerialEventDispatcher::ReceiveCallback(const ReceiveParams& params,
90 const std::string& data, 90 const std::string& data,
91 serial::ReceiveError error) { 91 serial::ReceiveError error) {
92 DCHECK(BrowserThread::CurrentlyOn(params.thread_id)); 92 DCHECK_CURRENTLY_ON(params.thread_id);
93 93
94 // Note that an error (e.g. timeout) does not necessarily mean that no data 94 // Note that an error (e.g. timeout) does not necessarily mean that no data
95 // was read, so we may fire an onReceive regardless of any error code. 95 // was read, so we may fire an onReceive regardless of any error code.
96 if (data.length() > 0) { 96 if (data.length() > 0) {
97 serial::ReceiveInfo receive_info; 97 serial::ReceiveInfo receive_info;
98 receive_info.connection_id = params.connection_id; 98 receive_info.connection_id = params.connection_id;
99 receive_info.data = data; 99 receive_info.data = data;
100 scoped_ptr<base::ListValue> args = serial::OnReceive::Create(receive_info); 100 scoped_ptr<base::ListValue> args = serial::OnReceive::Create(receive_info);
101 scoped_ptr<extensions::Event> event( 101 scoped_ptr<extensions::Event> event(
102 new extensions::Event(serial::OnReceive::kEventName, args.Pass())); 102 new extensions::Event(serial::OnReceive::kEventName, args.Pass()));
(...skipping 19 matching lines...) Expand all
122 122
123 // Queue up the next read operation. 123 // Queue up the next read operation.
124 BrowserThread::PostTask(params.thread_id, 124 BrowserThread::PostTask(params.thread_id,
125 FROM_HERE, 125 FROM_HERE,
126 base::Bind(&StartReceive, params)); 126 base::Bind(&StartReceive, params));
127 } 127 }
128 128
129 // static 129 // static
130 void SerialEventDispatcher::PostEvent(const ReceiveParams& params, 130 void SerialEventDispatcher::PostEvent(const ReceiveParams& params,
131 scoped_ptr<extensions::Event> event) { 131 scoped_ptr<extensions::Event> event) {
132 DCHECK(BrowserThread::CurrentlyOn(params.thread_id)); 132 DCHECK_CURRENTLY_ON(params.thread_id);
133 133
134 BrowserThread::PostTask( 134 BrowserThread::PostTask(
135 BrowserThread::UI, FROM_HERE, 135 BrowserThread::UI, FROM_HERE,
136 base::Bind(&DispatchEvent, 136 base::Bind(&DispatchEvent,
137 params.profile_id, 137 params.profile_id,
138 params.extension_id, 138 params.extension_id,
139 base::Passed(event.Pass()))); 139 base::Passed(event.Pass())));
140 } 140 }
141 141
142 // static 142 // static
143 void SerialEventDispatcher::DispatchEvent(void* profile_id, 143 void SerialEventDispatcher::DispatchEvent(void* profile_id,
144 const std::string& extension_id, 144 const std::string& extension_id,
145 scoped_ptr<extensions::Event> event) { 145 scoped_ptr<extensions::Event> event) {
146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 146 DCHECK_CURRENTLY_ON(BrowserThread::UI);
147 147
148 Profile* profile = reinterpret_cast<Profile*>(profile_id); 148 Profile* profile = reinterpret_cast<Profile*>(profile_id);
149 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) 149 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
150 return; 150 return;
151 151
152 EventRouter* router = ExtensionSystem::Get(profile)->event_router(); 152 EventRouter* router = ExtensionSystem::Get(profile)->event_router();
153 if (router) 153 if (router)
154 router->DispatchEventToExtension(extension_id, event.Pass()); 154 router->DispatchEventToExtension(extension_id, event.Pass());
155 } 155 }
156 156
157 } // namespace api 157 } // namespace api
158 158
159 } // namespace extensions 159 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698