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

Side by Side Diff: remoting/host/setup/native_messaging_host.cc

Issue 14979008: unittests for Chromoting native messaging host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename pipe.h->test_util.h, and fix Windows test failure Created 7 years, 6 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 "remoting/host/setup/native_messaging_host.h" 5 #include "remoting/host/setup/native_messaging_host.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 19 matching lines...) Expand all
30 LOG(ERROR) << "'config' dictionary not found"; 30 LOG(ERROR) << "'config' dictionary not found";
31 } 31 }
32 return result.Pass(); 32 return result.Pass();
33 } 33 }
34 34
35 } // namespace 35 } // namespace
36 36
37 namespace remoting { 37 namespace remoting {
38 38
39 NativeMessagingHost::NativeMessagingHost( 39 NativeMessagingHost::NativeMessagingHost(
40 scoped_ptr<DaemonController> daemon_controller,
40 base::PlatformFile input, 41 base::PlatformFile input,
41 base::PlatformFile output, 42 base::PlatformFile output,
42 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, 43 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
43 const base::Closure& quit_closure) 44 const base::Closure& quit_closure)
44 : caller_task_runner_(caller_task_runner), 45 : caller_task_runner_(caller_task_runner),
45 quit_closure_(quit_closure), 46 quit_closure_(quit_closure),
46 native_messaging_reader_(input), 47 native_messaging_reader_(input),
47 native_messaging_writer_(output), 48 native_messaging_writer_(output),
48 daemon_controller_(DaemonController::Create()), 49 daemon_controller_(daemon_controller.Pass()),
49 weak_factory_(this) { 50 weak_factory_(this) {
50 weak_ptr_ = weak_factory_.GetWeakPtr(); 51 weak_ptr_ = weak_factory_.GetWeakPtr();
51 } 52 }
52 53
53 NativeMessagingHost::~NativeMessagingHost() {} 54 NativeMessagingHost::~NativeMessagingHost() {}
54 55
55 void NativeMessagingHost::Start() { 56 void NativeMessagingHost::Start() {
56 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 57 DCHECK(caller_task_runner_->BelongsToCurrentThread());
57 58
58 native_messaging_reader_.Start( 59 native_messaging_reader_.Start(
59 base::Bind(&NativeMessagingHost::ProcessMessage, weak_ptr_), 60 base::Bind(&NativeMessagingHost::ProcessMessage, weak_ptr_),
60 base::Bind(&NativeMessagingHost::Shutdown, weak_ptr_)); 61 base::Bind(&NativeMessagingHost::Shutdown, weak_ptr_));
61 } 62 }
62 63
63 void NativeMessagingHost::Shutdown() { 64 void NativeMessagingHost::Shutdown() {
64 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 65 DCHECK(caller_task_runner_->BelongsToCurrentThread());
65 if (!quit_closure_.is_null()) { 66 if (!quit_closure_.is_null()) {
66 caller_task_runner_->PostTask(FROM_HERE, quit_closure_); 67 caller_task_runner_->PostTask(FROM_HERE, quit_closure_);
67 quit_closure_.Reset(); 68 quit_closure_.Reset();
68 } 69 }
69 } 70 }
70 71
71 void NativeMessagingHost::ProcessMessage(scoped_ptr<base::Value> message) { 72 void NativeMessagingHost::ProcessMessage(scoped_ptr<base::Value> message) {
72 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 73 DCHECK(caller_task_runner_->BelongsToCurrentThread());
74
75 // Don't process any more messages if Shutdown() has been called.
76 if (quit_closure_.is_null())
77 return;
78
73 const base::DictionaryValue* message_dict; 79 const base::DictionaryValue* message_dict;
74 if (!message->GetAsDictionary(&message_dict)) { 80 if (!message->GetAsDictionary(&message_dict)) {
75 LOG(ERROR) << "Expected DictionaryValue"; 81 LOG(ERROR) << "Expected DictionaryValue";
76 Shutdown(); 82 Shutdown();
83 return;
77 } 84 }
78 85
79 scoped_ptr<base::DictionaryValue> response_dict(new base::DictionaryValue()); 86 scoped_ptr<base::DictionaryValue> response_dict(new base::DictionaryValue());
80 87
81 // If the client supplies an ID, it will expect it in the response. This 88 // If the client supplies an ID, it will expect it in the response. This
82 // might be a string or a number, so cope with both. 89 // might be a string or a number, so cope with both.
83 const base::Value* id; 90 const base::Value* id;
84 if (message_dict->Get("id", &id)) 91 if (message_dict->Get("id", &id))
85 response_dict->Set("id", id->DeepCopy()); 92 response_dict->Set("id", id->DeepCopy());
86 93
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 void NativeMessagingHost::SendAsyncResult( 283 void NativeMessagingHost::SendAsyncResult(
277 scoped_ptr<base::DictionaryValue> response, 284 scoped_ptr<base::DictionaryValue> response,
278 DaemonController::AsyncResult result) { 285 DaemonController::AsyncResult result) {
279 // TODO(lambroslambrou): Send the result as a string instead of an integer, 286 // TODO(lambroslambrou): Send the result as a string instead of an integer,
280 // and update the web-app accordingly. See http://crbug.com/232135. 287 // and update the web-app accordingly. See http://crbug.com/232135.
281 response->SetInteger("result", result); 288 response->SetInteger("result", result);
282 SendResponse(response.Pass()); 289 SendResponse(response.Pass());
283 } 290 }
284 291
285 } // namespace remoting 292 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/setup/native_messaging_host.h ('k') | remoting/host/setup/native_messaging_host_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698