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 "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 Loading... |
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), | 101 force_keep_session_state_(false), |
102 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), |
112 quota_manager_proxy_(quota_manager_proxy), | 111 quota_manager_proxy_(quota_manager_proxy), |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::ClearSessionOnlyOrigins() { |
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 } | 835 if (special_storage_policy_->IsStorageProtected(origin_url)) |
838 if (special_storage_policy_.get() && | |
839 special_storage_policy_->IsStorageProtected(origin_url)) { | |
840 continue; | 836 continue; |
841 } | |
842 webkit_database::OriginInfo origin_info; | 837 webkit_database::OriginInfo origin_info; |
843 std::vector<string16> databases; | 838 std::vector<string16> databases; |
844 GetOriginInfo(*origin, &origin_info); | 839 GetOriginInfo(*origin, &origin_info); |
845 origin_info.GetAllDatabaseNames(&databases); | 840 origin_info.GetAllDatabaseNames(&databases); |
846 | 841 |
847 for (std::vector<string16>::iterator database = databases.begin(); | 842 for (std::vector<string16>::iterator database = databases.begin(); |
848 database != databases.end(); ++database) { | 843 database != databases.end(); ++database) { |
849 base::PlatformFile file_handle = base::CreatePlatformFile( | 844 base::PlatformFile file_handle = base::CreatePlatformFile( |
850 GetFullDBFilePath(*origin, *database), | 845 GetFullDBFilePath(*origin, *database), |
851 base::PLATFORM_FILE_OPEN_ALWAYS | | 846 base::PLATFORM_FILE_OPEN_ALWAYS | |
(...skipping 10 matching lines...) Expand all Loading... |
862 | 857 |
863 void DatabaseTracker::Shutdown() { | 858 void DatabaseTracker::Shutdown() { |
864 DCHECK(db_tracker_thread_.get()); | 859 DCHECK(db_tracker_thread_.get()); |
865 DCHECK(db_tracker_thread_->BelongsToCurrentThread()); | 860 DCHECK(db_tracker_thread_->BelongsToCurrentThread()); |
866 if (shutting_down_) { | 861 if (shutting_down_) { |
867 NOTREACHED(); | 862 NOTREACHED(); |
868 return; | 863 return; |
869 } | 864 } |
870 if (is_incognito_) | 865 if (is_incognito_) |
871 DeleteIncognitoDBDirectory(); | 866 DeleteIncognitoDBDirectory(); |
872 else if (!save_session_state_) | 867 else if (!force_keep_session_state_) |
873 ClearLocalState(clear_local_state_on_exit_); | 868 ClearSessionOnlyOrigins(); |
874 } | 869 } |
875 | 870 |
876 void DatabaseTracker::SetClearLocalStateOnExit(bool clear_local_state_on_exit) { | 871 void DatabaseTracker::SetForceKeepSessionState() { |
877 DCHECK(db_tracker_thread_.get()); | 872 DCHECK(db_tracker_thread_.get()); |
878 if (!db_tracker_thread_->BelongsToCurrentThread()) { | 873 if (!db_tracker_thread_->BelongsToCurrentThread()) { |
879 db_tracker_thread_->PostTask( | 874 db_tracker_thread_->PostTask( |
880 FROM_HERE, | 875 FROM_HERE, |
881 base::Bind(&DatabaseTracker::SetClearLocalStateOnExit, this, | 876 base::Bind(&DatabaseTracker::SetForceKeepSessionState, this)); |
882 clear_local_state_on_exit)); | |
883 return; | 877 return; |
884 } | 878 } |
885 if (shutting_down_) { | 879 force_keep_session_state_ = true; |
886 NOTREACHED(); | |
887 return; | |
888 } | |
889 clear_local_state_on_exit_ = clear_local_state_on_exit; | |
890 } | |
891 | |
892 void DatabaseTracker::SaveSessionState() { | |
893 DCHECK(db_tracker_thread_.get()); | |
894 if (!db_tracker_thread_->BelongsToCurrentThread()) { | |
895 db_tracker_thread_->PostTask( | |
896 FROM_HERE, | |
897 base::Bind(&DatabaseTracker::SaveSessionState, this)); | |
898 return; | |
899 } | |
900 save_session_state_ = true; | |
901 } | 880 } |
902 | 881 |
903 } // namespace webkit_database | 882 } // namespace webkit_database |
OLD | NEW |