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

Side by Side Diff: ios/chrome/browser/ui/webui/about_ui.cc

Issue 2537133002: Update brotli to v1.0.0-snapshot. (Closed)
Patch Set: Created 4 years 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
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 "ios/chrome/browser/ui/webui/about_ui.h" 5 #include "ios/chrome/browser/ui/webui/about_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <brotli/decode.h>
marq (ping after 24h) 2016/11/30 09:17:41 I have the same concerns about changing the includ
eustas 2016/12/02 11:49:41 Done.
8 #include <string> 9 #include <string>
9 #include <utility> 10 #include <utility>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/format_macros.h" 13 #include "base/format_macros.h"
13 #include "base/i18n/number_formatting.h" 14 #include "base/i18n/number_formatting.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/metrics/statistics_recorder.h" 16 #include "base/metrics/statistics_recorder.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
17 #include "components/grit/components_resources.h" 18 #include "components/grit/components_resources.h"
18 #include "google_apis/gaia/google_service_auth_error.h" 19 #include "google_apis/gaia/google_service_auth_error.h"
19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 20 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
20 #include "ios/chrome/browser/chrome_url_constants.h" 21 #include "ios/chrome/browser/chrome_url_constants.h"
21 #include "ios/web/public/url_data_source_ios.h" 22 #include "ios/web/public/url_data_source_ios.h"
22 #include "net/base/escape.h" 23 #include "net/base/escape.h"
23 #include "third_party/brotli/dec/decode.h"
24 #include "ui/base/device_form_factor.h" 24 #include "ui/base/device_form_factor.h"
25 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 namespace { 28 namespace {
29 29
30 const char kCreditsJsPath[] = "credits.js"; 30 const char kCreditsJsPath[] = "credits.js";
31 const char kStringsJsPath[] = "strings.js"; 31 const char kStringsJsPath[] = "strings.js";
32 32
33 class AboutUIHTMLSource : public web::URLDataSourceIOS { 33 class AboutUIHTMLSource : public web::URLDataSourceIOS {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // Add your data source here, in alphabetical order. 124 // Add your data source here, in alphabetical order.
125 if (source_name_ == kChromeUIChromeURLsHost) { 125 if (source_name_ == kChromeUIChromeURLsHost) {
126 response = ChromeURLs(); 126 response = ChromeURLs();
127 } else if (source_name_ == kChromeUICreditsHost) { 127 } else if (source_name_ == kChromeUICreditsHost) {
128 int idr = IDR_ABOUT_UI_CREDITS_HTML; 128 int idr = IDR_ABOUT_UI_CREDITS_HTML;
129 if (path == kCreditsJsPath) 129 if (path == kCreditsJsPath)
130 idr = IDR_ABOUT_UI_CREDITS_JS; 130 idr = IDR_ABOUT_UI_CREDITS_JS;
131 base::StringPiece raw_response = 131 base::StringPiece raw_response =
132 ResourceBundle::GetSharedInstance().GetRawDataResource(idr); 132 ResourceBundle::GetSharedInstance().GetRawDataResource(idr);
133 if (idr == IDR_ABOUT_UI_CREDITS_HTML) { 133 if (idr == IDR_ABOUT_UI_CREDITS_HTML) {
134 size_t decoded_size; 134 const uint8_t* in = reinterpret_cast<const uint8_t*>(raw_response.data());
marq (ping after 24h) 2016/11/30 09:17:41 |in| isn't a suitable variable name, since it does
eustas 2016/12/02 11:49:41 Semantics has changed - now decompression is strea
135 const uint8_t* encoded_response_buffer = 135 size_t available_in = raw_response.size();
marq (ping after 24h) 2016/11/30 09:17:41 Likewise, |available_in| isn't a good name here. |
eustas 2016/12/02 11:49:41 Done.
136 reinterpret_cast<const uint8_t*>(raw_response.data()); 136 BrotliDecoderState* decoder = BrotliDecoderCreateInstance(0, 0, 0);
marq (ping after 24h) 2016/11/30 09:17:41 I find 'BrotliDecoderState' a very counterintuitiv
marq (ping after 24h) 2016/11/30 09:17:41 Please insert inline comments to document the 0 pa
eustas 2016/12/02 11:49:41 Good point. I'll consider renaming this structure
137 CHECK(BrotliDecompressedSize(raw_response.size(), encoded_response_buffer, 137 CHECK(!!decoder);
138 &decoded_size)); 138 while (!BrotliDecoderIsFinished(decoder)) {
139 // Resizing the response and using it as the buffer Brotli decompresses 139 size_t available_out = 0;
marq (ping after 24h) 2016/11/30 09:17:41 Is |available_out| really something like |output_b
eustas 2016/12/02 11:49:41 Yup. Fixed.
140 // into. 140 CHECK(BrotliDecoderDecompressStream(decoder, &available_in, &in,
141 response.resize(decoded_size); 141 &available_out, 0,
marq (ping after 24h) 2016/11/30 09:17:41 Don't use 0 for null pointers here, either.
eustas 2016/12/02 11:49:41 Done.
142 CHECK(BrotliDecompressBuffer(raw_response.size(), encoded_response_buffer, 142 0) != BROTLI_DECODER_RESULT_ERROR);
143 &decoded_size, 143 const uint8_t* out = BrotliDecoderTakeOutput(decoder, &available_out);
144 reinterpret_cast<uint8_t*>(&response[0])) == 144 response.insert(response.end(), out, out + available_out);
145 BROTLI_RESULT_SUCCESS); 145 }
146 BrotliDecoderDestroyInstance(decoder);
146 } else { 147 } else {
147 response = raw_response.as_string(); 148 response = raw_response.as_string();
148 } 149 }
149 } else if (source_name_ == kChromeUIHistogramHost) { 150 } else if (source_name_ == kChromeUIHistogramHost) {
150 // Note: On other platforms, this is implemented in //content. If there is 151 // Note: On other platforms, this is implemented in //content. If there is
151 // ever a need for embedders other than //ios/chrome to use 152 // ever a need for embedders other than //ios/chrome to use
152 // chrome://histograms, this code could likely be moved to //io/web. 153 // chrome://histograms, this code could likely be moved to //io/web.
153 base::StatisticsRecorder::WriteHTMLGraph("", &response); 154 base::StatisticsRecorder::WriteHTMLGraph("", &response);
154 } 155 }
155 156
(...skipping 18 matching lines...) Expand all
174 return web::URLDataSourceIOS::ShouldDenyXFrameOptions(); 175 return web::URLDataSourceIOS::ShouldDenyXFrameOptions();
175 } 176 }
176 177
177 AboutUI::AboutUI(web::WebUIIOS* web_ui, const std::string& name) 178 AboutUI::AboutUI(web::WebUIIOS* web_ui, const std::string& name)
178 : web::WebUIIOSController(web_ui) { 179 : web::WebUIIOSController(web_ui) {
179 web::URLDataSourceIOS::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui), 180 web::URLDataSourceIOS::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
180 new AboutUIHTMLSource(name)); 181 new AboutUIHTMLSource(name));
181 } 182 }
182 183
183 AboutUI::~AboutUI() {} 184 AboutUI::~AboutUI() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698