| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/browser/page_state.h" | 8 #include "chrome/browser/page_state.h" |
| 9 #include "chrome/common/json_value_serializer.h" | 9 #include "chrome/common/json_value_serializer.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 void PageState::InitWithBytes(const std::string& bytes) { | 37 void PageState::InitWithBytes(const std::string& bytes) { |
| 38 // Reset our state. We create a new empty one just in case | 38 // Reset our state. We create a new empty one just in case |
| 39 // deserialization fails | 39 // deserialization fails |
| 40 state_.reset(new DictionaryValue); | 40 state_.reset(new DictionaryValue); |
| 41 | 41 |
| 42 JSONStringValueSerializer serializer(bytes); | 42 JSONStringValueSerializer serializer(bytes); |
| 43 Value* root = NULL; | 43 scoped_ptr<Value> root(serializer.Deserialize(NULL)); |
| 44 | 44 |
| 45 if (!serializer.Deserialize(&root, NULL)) | 45 if (!root.get()) { |
| 46 NOTREACHED(); | 46 NOTREACHED(); |
| 47 return; |
| 48 } |
| 47 | 49 |
| 48 if (root != NULL && root->GetType() == Value::TYPE_DICTIONARY) { | 50 if (root->GetType() == Value::TYPE_DICTIONARY) |
| 49 state_.reset(static_cast<DictionaryValue*>(root)); | 51 state_.reset(static_cast<DictionaryValue*>(root.release())); |
| 50 } else if (root) { | |
| 51 delete root; | |
| 52 } | |
| 53 } | 52 } |
| 54 | 53 |
| 55 void PageState::GetByteRepresentation(std::string* out) const { | 54 void PageState::GetByteRepresentation(std::string* out) const { |
| 56 JSONStringValueSerializer serializer(out); | 55 JSONStringValueSerializer serializer(out); |
| 57 if (!serializer.Serialize(*state_)) | 56 if (!serializer.Serialize(*state_)) |
| 58 NOTREACHED(); | 57 NOTREACHED(); |
| 59 } | 58 } |
| 60 | 59 |
| 61 void PageState::SetProperty(const std::wstring& key, | 60 void PageState::SetProperty(const std::wstring& key, |
| 62 const std::wstring& value) { | 61 const std::wstring& value) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 return false; | 99 return false; |
| 101 } | 100 } |
| 102 | 101 |
| 103 PageState* PageState::Copy() const { | 102 PageState* PageState::Copy() const { |
| 104 PageState* copy = new PageState(); | 103 PageState* copy = new PageState(); |
| 105 if (state_.get()) | 104 if (state_.get()) |
| 106 copy->state_.reset(static_cast<DictionaryValue*>(state_->DeepCopy())); | 105 copy->state_.reset(static_cast<DictionaryValue*>(state_->DeepCopy())); |
| 107 return copy; | 106 return copy; |
| 108 } | 107 } |
| 109 | 108 |
| OLD | NEW |