OLD | NEW |
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 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file.h" | 6 #include "base/files/file.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_file.h" | 9 #include "base/files/scoped_file.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 int write_flags = base::File::FLAG_CREATE | base::File::FLAG_WRITE; | 71 int write_flags = base::File::FLAG_CREATE | base::File::FLAG_WRITE; |
72 #if !defined(OS_POSIX) | 72 #if !defined(OS_POSIX) |
73 write_flags |= base::File::FLAG_ASYNC; | 73 write_flags |= base::File::FLAG_ASYNC; |
74 #endif | 74 #endif |
75 | 75 |
76 return scoped_ptr<NativeProcessLauncher>(new FakeLauncher( | 76 return scoped_ptr<NativeProcessLauncher>(new FakeLauncher( |
77 read_pipe.Pass(), | 77 read_pipe.Pass(), |
78 base::File(write_file, write_flags))); | 78 base::File(write_file, write_flags))); |
79 } | 79 } |
80 | 80 |
81 virtual void Launch(const GURL& origin, | 81 void Launch(const GURL& origin, |
82 const std::string& native_host_name, | 82 const std::string& native_host_name, |
83 LaunchedCallback callback) const override { | 83 LaunchedCallback callback) const override { |
84 callback.Run(NativeProcessLauncher::RESULT_SUCCESS, | 84 callback.Run(NativeProcessLauncher::RESULT_SUCCESS, |
85 base::kNullProcessHandle, | 85 base::kNullProcessHandle, |
86 read_file_.Pass(), write_file_.Pass()); | 86 read_file_.Pass(), write_file_.Pass()); |
87 } | 87 } |
88 | 88 |
89 private: | 89 private: |
90 mutable base::File read_file_; | 90 mutable base::File read_file_; |
91 mutable base::File write_file_; | 91 mutable base::File write_file_; |
92 }; | 92 }; |
93 | 93 |
(...skipping 11 matching lines...) Expand all Loading... |
105 } | 105 } |
106 | 106 |
107 virtual void TearDown() override { | 107 virtual void TearDown() override { |
108 if (native_message_host_.get()) { | 108 if (native_message_host_.get()) { |
109 BrowserThread::DeleteSoon( | 109 BrowserThread::DeleteSoon( |
110 BrowserThread::IO, FROM_HERE, native_message_host_.release()); | 110 BrowserThread::IO, FROM_HERE, native_message_host_.release()); |
111 } | 111 } |
112 base::RunLoop().RunUntilIdle(); | 112 base::RunLoop().RunUntilIdle(); |
113 } | 113 } |
114 | 114 |
115 virtual void PostMessageFromNativeHost(const std::string& message) override { | 115 void PostMessageFromNativeHost(const std::string& message) override { |
116 last_message_ = message; | 116 last_message_ = message; |
117 | 117 |
118 // Parse the message. | 118 // Parse the message. |
119 base::Value* parsed = base::JSONReader::Read(message); | 119 base::Value* parsed = base::JSONReader::Read(message); |
120 base::DictionaryValue* dict_value; | 120 base::DictionaryValue* dict_value; |
121 if (parsed && parsed->GetAsDictionary(&dict_value)) { | 121 if (parsed && parsed->GetAsDictionary(&dict_value)) { |
122 last_message_parsed_.reset(dict_value); | 122 last_message_parsed_.reset(dict_value); |
123 } else { | 123 } else { |
124 LOG(ERROR) << "Failed to parse " << message; | 124 LOG(ERROR) << "Failed to parse " << message; |
125 last_message_parsed_.reset(); | 125 last_message_parsed_.reset(); |
126 delete parsed; | 126 delete parsed; |
127 } | 127 } |
128 | 128 |
129 if (run_loop_) | 129 if (run_loop_) |
130 run_loop_->Quit(); | 130 run_loop_->Quit(); |
131 } | 131 } |
132 | 132 |
133 virtual void CloseChannel(const std::string& error_message) override { | 133 void CloseChannel(const std::string& error_message) override { |
134 channel_closed_ = true; | 134 channel_closed_ = true; |
135 if (run_loop_) | 135 if (run_loop_) |
136 run_loop_->Quit(); | 136 run_loop_->Quit(); |
137 } | 137 } |
138 | 138 |
139 protected: | 139 protected: |
140 std::string FormatMessage(const std::string& message) { | 140 std::string FormatMessage(const std::string& message) { |
141 uint32_t length = message.length(); | 141 uint32_t length = message.length(); |
142 return std::string(reinterpret_cast<char*>(&length), 4).append(message); | 142 return std::string(reinterpret_cast<char*>(&length), 4).append(message); |
143 } | 143 } |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 native_message_host_->Start(this); | 328 native_message_host_->Start(this); |
329 ASSERT_TRUE(native_message_host_.get()); | 329 ASSERT_TRUE(native_message_host_.get()); |
330 run_loop_.reset(new base::RunLoop()); | 330 run_loop_.reset(new base::RunLoop()); |
331 run_loop_->Run(); | 331 run_loop_->Run(); |
332 | 332 |
333 // The host should fail to start. | 333 // The host should fail to start. |
334 ASSERT_TRUE(channel_closed_); | 334 ASSERT_TRUE(channel_closed_); |
335 } | 335 } |
336 | 336 |
337 } // namespace extensions | 337 } // namespace extensions |
OLD | NEW |