1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <limits>
6
7 #include "chrome/browser/sessions/session_command.h"
8
9 #include "base/pickle.h"
10
SessionCommand(id_type id,size_type size)11 SessionCommand::SessionCommand(id_type id, size_type size)
12 : id_(id),
13 contents_(size, 0) {
14 }
15
SessionCommand(id_type id,const Pickle & pickle)16 SessionCommand::SessionCommand(id_type id, const Pickle& pickle)
17 : id_(id),
18 contents_(pickle.size(), 0) {
19 DCHECK(pickle.size() < std::numeric_limits<size_type>::max());
20 memcpy(contents(), pickle.data(), pickle.size());
21 }
22
GetPayload(void * dest,size_t count) const23 bool SessionCommand::GetPayload(void* dest, size_t count) const {
24 if (size() != count)
25 return false;
26 memcpy(dest, &(contents_[0]), count);
27 return true;
28 }
29
PayloadAsPickle() const30 Pickle* SessionCommand::PayloadAsPickle() const {
31 return new Pickle(contents(), static_cast<int>(size()));
32 }
33