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

Side by Side Diff: webkit/database/database_tracker.cc

Issue 10447117: Unwire the clear on exit preference from the storage systems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months 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 | Annotate | Revision Log
OLDNEW
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 "webkit/database/database_tracker.h" 5 #include "webkit/database/database_tracker.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 : origin_(origin), total_size_(total_size) {} 91 : origin_(origin), total_size_(total_size) {}
92 92
93 DatabaseTracker::DatabaseTracker( 93 DatabaseTracker::DatabaseTracker(
94 const FilePath& profile_path, 94 const FilePath& profile_path,
95 bool is_incognito, 95 bool is_incognito,
96 quota::SpecialStoragePolicy* special_storage_policy, 96 quota::SpecialStoragePolicy* special_storage_policy,
97 quota::QuotaManagerProxy* quota_manager_proxy, 97 quota::QuotaManagerProxy* quota_manager_proxy,
98 base::MessageLoopProxy* db_tracker_thread) 98 base::MessageLoopProxy* db_tracker_thread)
99 : is_initialized_(false), 99 : is_initialized_(false),
100 is_incognito_(is_incognito), 100 is_incognito_(is_incognito),
101 clear_local_state_on_exit_(false),
102 save_session_state_(false), 101 save_session_state_(false),
103 shutting_down_(false), 102 shutting_down_(false),
104 profile_path_(profile_path), 103 profile_path_(profile_path),
105 db_dir_(is_incognito_ ? 104 db_dir_(is_incognito_ ?
106 profile_path_.Append(kIncognitoDatabaseDirectoryName) : 105 profile_path_.Append(kIncognitoDatabaseDirectoryName) :
107 profile_path_.Append(kDatabaseDirectoryName)), 106 profile_path_.Append(kDatabaseDirectoryName)),
108 db_(new sql::Connection()), 107 db_(new sql::Connection()),
109 databases_table_(NULL), 108 databases_table_(NULL),
110 meta_table_(NULL), 109 meta_table_(NULL),
111 special_storage_policy_(special_storage_policy), 110 special_storage_policy_(special_storage_policy),
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 for (FileHandlesMap::iterator it = incognito_file_handles_.begin(); 802 for (FileHandlesMap::iterator it = incognito_file_handles_.begin();
804 it != incognito_file_handles_.end(); it++) 803 it != incognito_file_handles_.end(); it++)
805 base::ClosePlatformFile(it->second); 804 base::ClosePlatformFile(it->second);
806 805
807 FilePath incognito_db_dir = 806 FilePath incognito_db_dir =
808 profile_path_.Append(kIncognitoDatabaseDirectoryName); 807 profile_path_.Append(kIncognitoDatabaseDirectoryName);
809 if (file_util::DirectoryExists(incognito_db_dir)) 808 if (file_util::DirectoryExists(incognito_db_dir))
810 file_util::Delete(incognito_db_dir, true); 809 file_util::Delete(incognito_db_dir, true);
811 } 810 }
812 811
813 void DatabaseTracker::ClearLocalState(bool clear_all_databases) { 812 void DatabaseTracker::ClearLocalState() {
814 shutting_down_ = true; 813 shutting_down_ = true;
815 814
816 bool has_session_only_databases = 815 bool has_session_only_databases =
817 special_storage_policy_.get() && 816 special_storage_policy_.get() &&
818 special_storage_policy_->HasSessionOnlyOrigins(); 817 special_storage_policy_->HasSessionOnlyOrigins();
819 818
820 // Clearing only session-only databases, and there are none. 819 // Clearing only session-only databases, and there are none.
821 if (!clear_all_databases && !has_session_only_databases) 820 if (!has_session_only_databases)
822 return; 821 return;
823 822
824 if (!LazyInit()) 823 if (!LazyInit())
825 return; 824 return;
826 825
827 std::vector<string16> origin_identifiers; 826 std::vector<string16> origin_identifiers;
828 GetAllOriginIdentifiers(&origin_identifiers); 827 GetAllOriginIdentifiers(&origin_identifiers);
829 828
830 for (std::vector<string16>::iterator origin = origin_identifiers.begin(); 829 for (std::vector<string16>::iterator origin = origin_identifiers.begin();
831 origin != origin_identifiers.end(); ++origin) { 830 origin != origin_identifiers.end(); ++origin) {
832 GURL origin_url = 831 GURL origin_url =
833 webkit_database::DatabaseUtil::GetOriginFromIdentifier(*origin); 832 webkit_database::DatabaseUtil::GetOriginFromIdentifier(*origin);
834 if (!clear_all_databases && 833 if (!special_storage_policy_->IsStorageSessionOnly(origin_url))
835 !special_storage_policy_->IsStorageSessionOnly(origin_url)) {
836 continue; 834 continue;
837 }
838 if (special_storage_policy_.get() && 835 if (special_storage_policy_.get() &&
839 special_storage_policy_->IsStorageProtected(origin_url)) { 836 special_storage_policy_->IsStorageProtected(origin_url)) {
840 continue; 837 continue;
841 } 838 }
842 webkit_database::OriginInfo origin_info; 839 webkit_database::OriginInfo origin_info;
843 std::vector<string16> databases; 840 std::vector<string16> databases;
844 GetOriginInfo(*origin, &origin_info); 841 GetOriginInfo(*origin, &origin_info);
845 origin_info.GetAllDatabaseNames(&databases); 842 origin_info.GetAllDatabaseNames(&databases);
846 843
847 for (std::vector<string16>::iterator database = databases.begin(); 844 for (std::vector<string16>::iterator database = databases.begin();
(...skipping 15 matching lines...) Expand all
863 void DatabaseTracker::Shutdown() { 860 void DatabaseTracker::Shutdown() {
864 DCHECK(db_tracker_thread_.get()); 861 DCHECK(db_tracker_thread_.get());
865 DCHECK(db_tracker_thread_->BelongsToCurrentThread()); 862 DCHECK(db_tracker_thread_->BelongsToCurrentThread());
866 if (shutting_down_) { 863 if (shutting_down_) {
867 NOTREACHED(); 864 NOTREACHED();
868 return; 865 return;
869 } 866 }
870 if (is_incognito_) 867 if (is_incognito_)
871 DeleteIncognitoDBDirectory(); 868 DeleteIncognitoDBDirectory();
872 else if (!save_session_state_) 869 else if (!save_session_state_)
873 ClearLocalState(clear_local_state_on_exit_); 870 ClearLocalState();
874 }
875
876 void DatabaseTracker::SetClearLocalStateOnExit(bool clear_local_state_on_exit) {
877 DCHECK(db_tracker_thread_.get());
878 if (!db_tracker_thread_->BelongsToCurrentThread()) {
879 db_tracker_thread_->PostTask(
880 FROM_HERE,
881 base::Bind(&DatabaseTracker::SetClearLocalStateOnExit, this,
882 clear_local_state_on_exit));
883 return;
884 }
885 if (shutting_down_) {
886 NOTREACHED();
887 return;
888 }
889 clear_local_state_on_exit_ = clear_local_state_on_exit;
890 } 871 }
891 872
892 void DatabaseTracker::SaveSessionState() { 873 void DatabaseTracker::SaveSessionState() {
893 DCHECK(db_tracker_thread_.get()); 874 DCHECK(db_tracker_thread_.get());
894 if (!db_tracker_thread_->BelongsToCurrentThread()) { 875 if (!db_tracker_thread_->BelongsToCurrentThread()) {
895 db_tracker_thread_->PostTask( 876 db_tracker_thread_->PostTask(
896 FROM_HERE, 877 FROM_HERE,
897 base::Bind(&DatabaseTracker::SaveSessionState, this)); 878 base::Bind(&DatabaseTracker::SaveSessionState, this));
898 return; 879 return;
899 } 880 }
900 save_session_state_ = true; 881 save_session_state_ = true;
901 } 882 }
902 883
903 } // namespace webkit_database 884 } // namespace webkit_database
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698