| 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/common/extensions/extension_localization_peer.h" | 5 #include "chrome/common/extensions/extension_localization_peer.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/common/extensions/extension_message_bundle.h" | 9 #include "chrome/common/extensions/extension_message_bundle.h" |
| 10 #include "chrome/common/extensions/extension_messages.h" | 10 #include "chrome/common/extensions/extension_messages.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 response_info_ = info; | 59 response_info_ = info; |
| 60 } | 60 } |
| 61 | 61 |
| 62 void ExtensionLocalizationPeer::OnReceivedData(const char* data, | 62 void ExtensionLocalizationPeer::OnReceivedData(const char* data, |
| 63 int data_length, | 63 int data_length, |
| 64 int encoded_data_length) { | 64 int encoded_data_length) { |
| 65 data_.append(data, data_length); | 65 data_.append(data, data_length); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ExtensionLocalizationPeer::OnCompletedRequest( | 68 void ExtensionLocalizationPeer::OnCompletedRequest( |
| 69 const net::URLRequestStatus& status, | 69 int error_code, |
| 70 const std::string& security_info, | 70 const std::string& security_info, |
| 71 const base::TimeTicks& completion_time) { | 71 const base::TimeTicks& completion_time) { |
| 72 // Make sure we delete ourselves at the end of this call. | 72 // Make sure we delete ourselves at the end of this call. |
| 73 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); | 73 scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); |
| 74 | 74 |
| 75 // Give sub-classes a chance at altering the data. | 75 // Give sub-classes a chance at altering the data. |
| 76 if (status.status() != net::URLRequestStatus::SUCCESS) { | 76 if (!net::IsSuccess(error_code)) { |
| 77 // We failed to load the resource. | 77 // We failed to load the resource. |
| 78 original_peer_->OnReceivedResponse(response_info_); | 78 original_peer_->OnReceivedResponse(response_info_); |
| 79 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, | 79 original_peer_->OnCompletedRequest(net::ERR_ABORTED, security_info, |
| 80 net::ERR_ABORTED); | 80 completion_time); |
| 81 original_peer_->OnCompletedRequest(status, security_info, completion_time); | |
| 82 return; | 81 return; |
| 83 } | 82 } |
| 84 | 83 |
| 85 ReplaceMessages(); | 84 ReplaceMessages(); |
| 86 | 85 |
| 87 original_peer_->OnReceivedResponse(response_info_); | 86 original_peer_->OnReceivedResponse(response_info_); |
| 88 if (!data_.empty()) | 87 if (!data_.empty()) |
| 89 original_peer_->OnReceivedData(data_.data(), | 88 original_peer_->OnReceivedData(data_.data(), |
| 90 static_cast<int>(data_.size()), | 89 static_cast<int>(data_.size()), |
| 91 -1); | 90 -1); |
| 92 original_peer_->OnCompletedRequest(status, security_info, completion_time); | 91 original_peer_->OnCompletedRequest(error_code, security_info, |
| 92 completion_time); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void ExtensionLocalizationPeer::ReplaceMessages() { | 95 void ExtensionLocalizationPeer::ReplaceMessages() { |
| 96 if (!message_sender_ || data_.empty()) | 96 if (!message_sender_ || data_.empty()) |
| 97 return; | 97 return; |
| 98 | 98 |
| 99 if (!request_url_.is_valid()) | 99 if (!request_url_.is_valid()) |
| 100 return; | 100 return; |
| 101 | 101 |
| 102 std::string extension_id = request_url_.host(); | 102 std::string extension_id = request_url_.host(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 114 | 114 |
| 115 l10n_messages = GetL10nMessagesMap(extension_id); | 115 l10n_messages = GetL10nMessagesMap(extension_id); |
| 116 } | 116 } |
| 117 | 117 |
| 118 std::string error; | 118 std::string error; |
| 119 if (ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary( | 119 if (ExtensionMessageBundle::ReplaceMessagesWithExternalDictionary( |
| 120 *l10n_messages, &data_, &error)) { | 120 *l10n_messages, &data_, &error)) { |
| 121 data_.resize(data_.size()); | 121 data_.resize(data_.size()); |
| 122 } | 122 } |
| 123 } | 123 } |
| OLD | NEW |