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

Side by Side Diff: tools/battor_agent/battor_agent.cc

Issue 1869503004: Convert //tools to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, change iwyu fixes for converted directories to include <memory> Created 4 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
« no previous file with comments | « tools/battor_agent/battor_agent.h ('k') | tools/battor_agent/battor_agent_bin.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "tools/battor_agent/battor_agent.h" 5 #include "tools/battor_agent/battor_agent.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 reinterpret_cast<const BattOrControlMessageAck*>(msg.data()); 48 reinterpret_cast<const BattOrControlMessageAck*>(msg.data());
49 49
50 if (ack->type != control_message_type) 50 if (ack->type != control_message_type)
51 return false; 51 return false;
52 52
53 return true; 53 return true;
54 } 54 }
55 55
56 // Attempts to decode the specified vector of bytes decodes to a valid EEPROM. 56 // Attempts to decode the specified vector of bytes decodes to a valid EEPROM.
57 // Returns the new EEPROM, or nullptr if unsuccessful. 57 // Returns the new EEPROM, or nullptr if unsuccessful.
58 scoped_ptr<BattOrEEPROM> ParseEEPROM(BattOrMessageType message_type, 58 std::unique_ptr<BattOrEEPROM> ParseEEPROM(BattOrMessageType message_type,
59 const vector<char>& msg) { 59 const vector<char>& msg) {
60 if (message_type != BATTOR_MESSAGE_TYPE_CONTROL_ACK) 60 if (message_type != BATTOR_MESSAGE_TYPE_CONTROL_ACK)
61 return nullptr; 61 return nullptr;
62 62
63 if (msg.size() != sizeof(BattOrEEPROM)) 63 if (msg.size() != sizeof(BattOrEEPROM))
64 return nullptr; 64 return nullptr;
65 65
66 scoped_ptr<BattOrEEPROM> eeprom(new BattOrEEPROM()); 66 std::unique_ptr<BattOrEEPROM> eeprom(new BattOrEEPROM());
67 memcpy(eeprom.get(), msg.data(), sizeof(BattOrEEPROM)); 67 memcpy(eeprom.get(), msg.data(), sizeof(BattOrEEPROM));
68 return eeprom; 68 return eeprom;
69 } 69 }
70 70
71 // Returns true if the specified vector of bytes decodes to a valid BattOr 71 // Returns true if the specified vector of bytes decodes to a valid BattOr
72 // samples frame. The frame header and samples are returned via the frame_header 72 // samples frame. The frame header and samples are returned via the frame_header
73 // and samples paramaters. 73 // and samples paramaters.
74 bool ParseSampleFrame(BattOrMessageType type, 74 bool ParseSampleFrame(BattOrMessageType type,
75 const vector<char>& msg, 75 const vector<char>& msg,
76 uint32_t expected_sequence_number, 76 uint32_t expected_sequence_number,
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 num_read_attempts_ = 1; 237 num_read_attempts_ = 1;
238 PerformAction(Action::READ_CURRENT_SAMPLE); 238 PerformAction(Action::READ_CURRENT_SAMPLE);
239 return; 239 return;
240 default: 240 default:
241 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE); 241 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE);
242 } 242 }
243 } 243 }
244 244
245 void BattOrAgent::OnMessageRead(bool success, 245 void BattOrAgent::OnMessageRead(bool success,
246 BattOrMessageType type, 246 BattOrMessageType type,
247 scoped_ptr<vector<char>> bytes) { 247 std::unique_ptr<vector<char>> bytes) {
248 // Return immediately if whatever action we were trying to perform already 248 // Return immediately if whatever action we were trying to perform already
249 // timed out. 249 // timed out.
250 if (timeout_callback_.IsCancelled()) 250 if (timeout_callback_.IsCancelled())
251 return; 251 return;
252 timeout_callback_.Cancel(); 252 timeout_callback_.Cancel();
253 253
254 if (!success) { 254 if (!success) {
255 switch (last_action_) { 255 switch (last_action_) {
256 case Action::READ_EEPROM: 256 case Action::READ_EEPROM:
257 case Action::READ_CALIBRATION_FRAME: 257 case Action::READ_CALIBRATION_FRAME:
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 if (clock_sync_marker != clock_sync_markers_.end()) 561 if (clock_sync_marker != clock_sync_markers_.end())
562 trace_stream << " <" << clock_sync_marker->second << ">"; 562 trace_stream << " <" << clock_sync_marker->second << ">";
563 563
564 trace_stream << std::endl; 564 trace_stream << std::endl;
565 } 565 }
566 566
567 return trace_stream.str(); 567 return trace_stream.str();
568 } 568 }
569 569
570 } // namespace battor 570 } // namespace battor
OLDNEW
« no previous file with comments | « tools/battor_agent/battor_agent.h ('k') | tools/battor_agent/battor_agent_bin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698