Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/translate/content/renderer/translate_helper.h" | 5 #include "components/translate/content/renderer/translate_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "components/translate/content/common/translate_messages.h" | 15 #include "components/translate/content/common/translate_messages.h" |
| 16 #include "components/translate/content/renderer/renderer_cld_data_provider.h" | |
| 17 #include "components/translate/content/renderer/static_renderer_cld_data_provide r.h" | |
| 16 #include "components/translate/core/common/translate_constants.h" | 18 #include "components/translate/core/common/translate_constants.h" |
| 17 #include "components/translate/core/common/translate_metrics.h" | 19 #include "components/translate/core/common/translate_metrics.h" |
| 18 #include "components/translate/core/common/translate_util.h" | 20 #include "components/translate/core/common/translate_util.h" |
| 19 #include "components/translate/core/language_detection/language_detection_util.h " | 21 #include "components/translate/core/language_detection/language_detection_util.h " |
| 20 #include "content/public/common/content_constants.h" | 22 #include "content/public/common/content_constants.h" |
| 21 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
| 22 #include "content/public/renderer/render_thread.h" | 24 #include "content/public/renderer/render_thread.h" |
| 23 #include "content/public/renderer/render_view.h" | 25 #include "content/public/renderer/render_view.h" |
| 24 #include "ipc/ipc_platform_file.h" | 26 #include "ipc/ipc_platform_file.h" |
| 25 #include "third_party/WebKit/public/web/WebDocument.h" | 27 #include "third_party/WebKit/public/web/WebDocument.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 //////////////////////////////////////////////////////////////////////////////// | 77 //////////////////////////////////////////////////////////////////////////////// |
| 76 // TranslateHelper, public: | 78 // TranslateHelper, public: |
| 77 // | 79 // |
| 78 TranslateHelper::TranslateHelper(content::RenderView* render_view, | 80 TranslateHelper::TranslateHelper(content::RenderView* render_view, |
| 79 int world_id, | 81 int world_id, |
| 80 int extension_group, | 82 int extension_group, |
| 81 const std::string& extension_scheme) | 83 const std::string& extension_scheme) |
| 82 : content::RenderViewObserver(render_view), | 84 : content::RenderViewObserver(render_view), |
| 83 page_seq_no_(0), | 85 page_seq_no_(0), |
| 84 translation_pending_(false), | 86 translation_pending_(false), |
| 85 cld_data_provider_(translate::CreateRendererCldDataProviderFor(this)), | 87 cld_data_provider_( |
| 88 static_cast<translate::RendererCldDataProvider*>(NULL)), | |
| 86 cld_data_polling_started_(false), | 89 cld_data_polling_started_(false), |
| 87 cld_data_polling_canceled_(false), | 90 cld_data_polling_canceled_(false), |
| 88 deferred_page_capture_(false), | 91 deferred_page_capture_(false), |
| 89 deferred_page_seq_no_(-1), | 92 deferred_page_seq_no_(-1), |
| 90 world_id_(world_id), | 93 world_id_(world_id), |
| 91 extension_group_(extension_group), | 94 extension_group_(extension_group), |
| 92 extension_scheme_(extension_scheme), | 95 extension_scheme_(extension_scheme), |
| 93 weak_method_factory_(this) { | 96 weak_method_factory_(this) { |
| 97 if (!translate::RendererCldDataProvider::IsInitialized()) { | |
| 98 // No provider is yet set for this renderer process. Initialize one now. | |
| 99 translate::RendererCldDataProvider* provider; | |
| 100 | |
| 101 // Note: Customize the data source and provider here, as desired. | |
|
Andrew Hayden (chromium.org)
2014/09/26 10:22:49
This comment should look like the other one for ma
Andrew Hayden (chromium.org)
2014/10/28 15:18:39
Done.
| |
| 102 provider = new translate::StaticRendererCldDataProvider(); | |
| 103 | |
| 104 translate::RendererCldDataProvider::Set(provider, false); | |
| 105 } | |
| 106 cld_data_provider_.reset(translate::RendererCldDataProvider::Get()); | |
| 94 } | 107 } |
| 95 | 108 |
| 96 TranslateHelper::~TranslateHelper() { | 109 TranslateHelper::~TranslateHelper() { |
| 97 CancelPendingTranslation(); | 110 CancelPendingTranslation(); |
| 98 CancelCldDataPolling(); | 111 CancelCldDataPolling(); |
| 99 } | 112 } |
| 100 | 113 |
| 101 void TranslateHelper::PrepareForUrl(const GURL& url) { | 114 void TranslateHelper::PrepareForUrl(const GURL& url) { |
| 102 ++page_seq_no_; | 115 ++page_seq_no_; |
| 103 Send(new ChromeViewHostMsg_TranslateAssignedSequenceNumber( | 116 Send(new ChromeViewHostMsg_TranslateAssignedSequenceNumber( |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 // this, everything should start being ON_TIME. This should never run more | 642 // this, everything should start being ON_TIME. This should never run more |
| 630 // than twice in a page load, under any conditions. | 643 // than twice in a page load, under any conditions. |
| 631 // Also note that language detection is triggered off of a delay AFTER the | 644 // Also note that language detection is triggered off of a delay AFTER the |
| 632 // page load completed event has fired, making this very much off the critical | 645 // page load completed event has fired, making this very much off the critical |
| 633 // path. | 646 // path. |
| 634 content::RenderThread::Get()->UpdateHistograms( | 647 content::RenderThread::Get()->UpdateHistograms( |
| 635 content::kHistogramSynchronizerReservedSequenceNumber); | 648 content::kHistogramSynchronizerReservedSequenceNumber); |
| 636 } | 649 } |
| 637 | 650 |
| 638 } // namespace translate | 651 } // namespace translate |
| OLD | NEW |