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 "chrome/browser/translate/translate_manager.h" | 5 #include "chrome/browser/translate/translate_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // before attempting a translation. | 77 // before attempting a translation. |
78 const int kTranslateLoadCheckDelayMs = 150; | 78 const int kTranslateLoadCheckDelayMs = 150; |
79 | 79 |
80 // The maximum number of attempts we'll do to see if the page has finshed | 80 // The maximum number of attempts we'll do to see if the page has finshed |
81 // loading before giving up the translation | 81 // loading before giving up the translation |
82 const int kMaxTranslateLoadCheckAttempts = 20; | 82 const int kMaxTranslateLoadCheckAttempts = 20; |
83 | 83 |
84 } // namespace | 84 } // namespace |
85 | 85 |
86 TranslateManager::~TranslateManager() { | 86 TranslateManager::~TranslateManager() { |
| 87 // CleanupPendingUrlFetcher should be called ahead of destructing. |
| 88 DCHECK(language_list_.get() == NULL); |
| 89 DCHECK(script_.get() == NULL); |
| 90 |
87 weak_method_factory_.InvalidateWeakPtrs(); | 91 weak_method_factory_.InvalidateWeakPtrs(); |
88 } | 92 } |
89 | 93 |
90 // static | 94 // static |
91 TranslateManager* TranslateManager::GetInstance() { | 95 TranslateManager* TranslateManager::GetInstance() { |
92 return Singleton<TranslateManager>::get(); | 96 return Singleton<TranslateManager>::get(); |
93 } | 97 } |
94 | 98 |
95 // static | 99 // static |
96 bool TranslateManager::IsTranslatableURL(const GURL& url) { | 100 bool TranslateManager::IsTranslatableURL(const GURL& url) { |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 (prefs != NULL && !prefs->GetBoolean(prefs::kEnableTranslate))) { | 631 (prefs != NULL && !prefs->GetBoolean(prefs::kEnableTranslate))) { |
628 return; | 632 return; |
629 } | 633 } |
630 | 634 |
631 if (language_list_.get()) | 635 if (language_list_.get()) |
632 language_list_->RequestLanguageList(); | 636 language_list_->RequestLanguageList(); |
633 else | 637 else |
634 NOTREACHED(); | 638 NOTREACHED(); |
635 } | 639 } |
636 | 640 |
637 void TranslateManager::CleanupPendingUlrFetcher() { | 641 void TranslateManager::CleanupPendingUrlFetcher() { |
638 language_list_.reset(); | 642 language_list_.reset(); |
639 script_.reset(); | 643 script_.reset(); |
640 } | 644 } |
641 | 645 |
642 void TranslateManager::OnTranslateScriptFetchComplete( | 646 void TranslateManager::OnTranslateScriptFetchComplete( |
643 bool success, const std::string& data) { | 647 bool success, const std::string& data) { |
644 std::vector<PendingRequest>::const_iterator iter; | 648 std::vector<PendingRequest>::const_iterator iter; |
645 for (iter = pending_requests_.begin(); iter != pending_requests_.end(); | 649 for (iter = pending_requests_.begin(); iter != pending_requests_.end(); |
646 ++iter) { | 650 ++iter) { |
647 const PendingRequest& request = *iter; | 651 const PendingRequest& request = *iter; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 // so we are more aggressive about showing the shortcut to never translate. | 721 // so we are more aggressive about showing the shortcut to never translate. |
718 #if defined(OS_ANDROID) | 722 #if defined(OS_ANDROID) |
719 config.never_translate_min_count = 1; | 723 config.never_translate_min_count = 1; |
720 #else | 724 #else |
721 config.never_translate_min_count = 3; | 725 config.never_translate_min_count = 3; |
722 #endif // defined(OS_ANDROID) | 726 #endif // defined(OS_ANDROID) |
723 | 727 |
724 config.always_translate_min_count = 3; | 728 config.always_translate_min_count = 3; |
725 return config; | 729 return config; |
726 } | 730 } |
OLD | NEW |