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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc

Issue 290173008: Refactor PickleIterator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 7 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
« base/pickle.cc ('K') | « base/pickle_unittest.cc ('k') | no next file » | 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 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 135
136 virtual void CloseChannel(int port_id, 136 virtual void CloseChannel(int port_id,
137 const std::string& error_message) OVERRIDE { 137 const std::string& error_message) OVERRIDE {
138 channel_closed_ = true; 138 channel_closed_ = true;
139 if (run_loop_) 139 if (run_loop_)
140 run_loop_->Quit(); 140 run_loop_->Quit();
141 } 141 }
142 142
143 protected: 143 protected:
144 std::string FormatMessage(const std::string& message) { 144 std::string FormatMessage(const std::string& message) {
145 Pickle pickle; 145 uint32_t length = message.length();
146 pickle.WriteString(message); 146 return std::string(reinterpret_cast<char*>(&length), 4).append(message);
jar (doing other things) 2014/05/22 02:51:00 The original code is confusing for other reasons..
halyavin 2014/05/22 04:05:25 I made Pickle payload size aligned to 4 bytes and
jar (doing other things) 2014/05/23 21:22:04 Yes... SGTM. thx.
147 return std::string(const_cast<const Pickle*>(&pickle)->payload(),
148 pickle.payload_size());
149 } 147 }
150 148
151 base::FilePath CreateTempFileWithMessage(const std::string& message) { 149 base::FilePath CreateTempFileWithMessage(const std::string& message) {
152 base::FilePath filename; 150 base::FilePath filename;
153 if (!base::CreateTemporaryFileInDir(temp_dir_.path(), &filename)) 151 if (!base::CreateTemporaryFileInDir(temp_dir_.path(), &filename))
154 return base::FilePath(); 152 return base::FilePath();
155 153
156 std::string message_with_header = FormatMessage(message); 154 std::string message_with_header = FormatMessage(message);
157 int bytes_written = base::WriteFile( 155 int bytes_written = base::WriteFile(
158 filename, message_with_header.data(), message_with_header.size()); 156 filename, message_with_header.data(), message_with_header.size());
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ScopedTestNativeMessagingHost::kHostName, 0, false); 312 ScopedTestNativeMessagingHost::kHostName, 0, false);
315 ASSERT_TRUE(native_message_process_host_.get()); 313 ASSERT_TRUE(native_message_process_host_.get());
316 run_loop_.reset(new base::RunLoop()); 314 run_loop_.reset(new base::RunLoop());
317 run_loop_->Run(); 315 run_loop_->Run();
318 316
319 // The host should fail to start. 317 // The host should fail to start.
320 ASSERT_TRUE(channel_closed_); 318 ASSERT_TRUE(channel_closed_);
321 } 319 }
322 320
323 } // namespace extensions 321 } // namespace extensions
OLDNEW
« base/pickle.cc ('K') | « base/pickle_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698