| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 5 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 | 11 |
| 12 const char* BrowserActionDragData::kClipboardFormatString = | 12 const char* BrowserActionDragData::kClipboardFormatString = |
| 13 "chromium/x-browser-actions"; | 13 "chromium/x-browser-actions"; |
| 14 | 14 |
| 15 BrowserActionDragData::BrowserActionDragData() | 15 BrowserActionDragData::BrowserActionDragData() |
| 16 : profile_id_(0), index_(-1) { | 16 : profile_(NULL), index_(-1) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 BrowserActionDragData::BrowserActionDragData( | 19 BrowserActionDragData::BrowserActionDragData( |
| 20 const std::string& id, int index) | 20 const std::string& id, int index) |
| 21 : profile_id_(0), id_(id), index_(index) { | 21 : profile_(NULL), id_(id), index_(index) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool BrowserActionDragData::IsFromProfile(Profile* profile) const { | 24 bool BrowserActionDragData::IsFromProfile(Profile* profile) const { |
| 25 return (profile_id_ == profile->GetRuntimeId()); | 25 return profile_ == profile; |
| 26 } | 26 } |
| 27 | 27 |
| 28 #if defined(TOOLKIT_VIEWS) | 28 #if defined(TOOLKIT_VIEWS) |
| 29 void BrowserActionDragData::Write( | 29 void BrowserActionDragData::Write( |
| 30 Profile* profile, ui::OSExchangeData* data) const { | 30 Profile* profile, ui::OSExchangeData* data) const { |
| 31 DCHECK(data); | 31 DCHECK(data); |
| 32 Pickle data_pickle; | 32 Pickle data_pickle; |
| 33 WriteToPickle(profile, &data_pickle); | 33 WriteToPickle(profile, &data_pickle); |
| 34 data->SetPickledData(GetBrowserActionCustomFormat(), data_pickle); | 34 data->SetPickledData(GetBrowserActionCustomFormat(), data_pickle); |
| 35 } | 35 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 58 format_valid = true; | 58 format_valid = true; |
| 59 format = ui::OSExchangeData::RegisterCustomFormat( | 59 format = ui::OSExchangeData::RegisterCustomFormat( |
| 60 BrowserActionDragData::kClipboardFormatString); | 60 BrowserActionDragData::kClipboardFormatString); |
| 61 } | 61 } |
| 62 return format; | 62 return format; |
| 63 } | 63 } |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 void BrowserActionDragData::WriteToPickle( | 66 void BrowserActionDragData::WriteToPickle( |
| 67 Profile* profile, Pickle* pickle) const { | 67 Profile* profile, Pickle* pickle) const { |
| 68 ProfileId profile_id = profile->GetRuntimeId(); | 68 pickle->WriteBytes(&profile, sizeof(profile)); |
| 69 pickle->WriteBytes(&profile_id, sizeof(profile_id)); | |
| 70 pickle->WriteString(id_); | 69 pickle->WriteString(id_); |
| 71 pickle->WriteSize(index_); | 70 pickle->WriteSize(index_); |
| 72 } | 71 } |
| 73 | 72 |
| 74 bool BrowserActionDragData::ReadFromPickle(Pickle* pickle) { | 73 bool BrowserActionDragData::ReadFromPickle(Pickle* pickle) { |
| 75 void* data_iterator = NULL; | 74 void* data_iterator = NULL; |
| 76 | 75 |
| 77 const char* tmp; | 76 const char* tmp; |
| 78 if (!pickle->ReadBytes(&data_iterator, &tmp, sizeof(profile_id_))) | 77 if (!pickle->ReadBytes(&data_iterator, &tmp, sizeof(profile_))) |
| 79 return false; | 78 return false; |
| 80 memcpy(&profile_id_, tmp, sizeof(profile_id_)); | 79 memcpy(&profile_, tmp, sizeof(profile_)); |
| 81 | 80 |
| 82 if (!pickle->ReadString(&data_iterator, &id_)) | 81 if (!pickle->ReadString(&data_iterator, &id_)) |
| 83 return false; | 82 return false; |
| 84 | 83 |
| 85 if (!pickle->ReadSize(&data_iterator, &index_)) | 84 if (!pickle->ReadSize(&data_iterator, &index_)) |
| 86 return false; | 85 return false; |
| 87 | 86 |
| 88 return true; | 87 return true; |
| 89 } | 88 } |
| OLD | NEW |